[Tkinter-discuss] Scale widget fires command on entering mainloop?

david.giesen at kodak.com david.giesen at kodak.com
Fri Nov 7 14:18:18 CET 2008

Hi -

I'm trying to figure out why the Tkinter Scale widget seems to fire its 
command callback when the root.mainloop() is executed.  This seems in 
contrast with other widgets like the Button that only fire the command 
callback in response to user interaction.  I'm using Windows XP, the 
Python 2.5 and, based on the folder names in the Python\tcl folder, tk8.4 
and tcl8.4.

Below is an example script.  It sets up two sliders who get values 
initialized in two different ways.  The print statements show that the 
sliders are initialized and packed, and THEN the command callbacks occur 
once the root.mainloop() statement executes.

Can suggest a way to prevent this from happening?  I could have each 
callback do no action the first time it is called, I suppose.  But I 
wonder if I'm simply doing something wrong, or if I'm assuming a behavior 
from Tkinter that I should not, or if I've encountered something 

Thanks in advance!

Dave Giesen

# Start of demo script
import Tkinter as Tk
import gwidgets as gw

root = Tk.Tk()
def printme1(value):
        print 'Scale # 1 just called back with value:', value
scalevar = gw.iVar(7)
scale1 = Tk.Scale(root, command=printme1, variable=scalevar)
print 'Scale #1 initialized with value:', scale1.get()

def printme2(value):
        print 'Scale # 2 just called back with value:', value
scale2 = Tk.Scale(root)
print 'Scale #2 initialized with value: ', scale2.get()
print 'Scale #2 just set to value: ', scale2.get()

print 'Now packing scales'
print 'Done packing scales'

# End of demo script

More information about the Tkinter-discuss mailing list