[Tkinter-discuss] running a command with input from a widget
Amit Finkler
amit.finkler at gmail.com
Tue Apr 15 16:20:21 CEST 2008
Hi,
I created a function which has the following format,
def setrange_rod(heater_range):
""" Set heater range (0,1,2,3) to Lakeshore 330 """
lakeshore = devices.getDeviceByAddress(int(LakeAdr.get()))
lakeshore.setrange(heater_range)
Never mind right now what the first line in the function does. It is
suffice to say that it creates the lakeshore class and that if I call it
from the console with the .setrange(heater_range), it works
(heater_range in my case is either 0, 1, 2 or 3)
I'm trying to call it from a Menu widget
heater = Menu( win3 , tearoff = 0 )
set_range_rod = Menu( heater, tearoff = 0 )
set_range_rod.add_command( label = "OFF", command = setrange_rod(0))
set_range_rod.add_command( label = "LOW", command = setrange_rod(1))
set_range_rod.add_command( label = "MEDIUM", command = setrange_rod(2))
set_range_rod.add_command( label = "HIGH", command = setrange_rod(3))
heater.add_cascade(label = "Rod", menu = set_range_rod)
win3.config( menu=heater )
When I import the module, it automatically sets itself on the last
option ("HIGH") and I cannot change it by choosing one of the other
options in the menu. Does this happen because I wrote a "command =
setrange(specific_value)"? If I use the same code but with a inputless
function, i.e., "command = setrange_rod", assuming the setrange_rod is
an inputless function - everything works fine. Hence my question.
I apologize if my code is a bit messy, but I'm in the stages of
renovations in the main code (aren't we always?). If you want, I can
send it in its full glory, but then I think that decent programmers
would start vomiting... :-)
Any help or suggestions will be appreciated.
Amit.
More information about the Tkinter-discuss
mailing list