Tk button help
Laura Creighton
lac at strakt.com
Tue Feb 12 13:42:22 EST 2002
You can't pass arguments to bindings like:
Button(top, text='Enter Leaf N', command = test.run(G)).pack(side=RIGHT, fill = BOTH)
you just want the NAME of the function. This works great when there are no
arguments. If there are, get out the lambda.
This works:
from __future__ import nested_scopes #I am still using 2.1
from Tkinter import *
def run(arg):
from tkSimpleDialog import askfloat
N = askfloat('N', 'Leaf N (50 - 250 mmol m-2) ')
print N, arg
###########################
if __name__ == '__main__':
root = Tk()
quit = Button(root, text="QUIT", fg="red", command=root.quit)
quit.pack(side='left')
B = Button(root, text='Enter Leaf N', command=lambda : run('hi there'))
B.pack(side=RIGHT, fill= BOTH)
root.mainloop()
So you might want command=lambda s=self, arg=4.0 : s.run(arg) or some such.
Laura Creighton
More information about the Python-list
mailing list