[Tkinter-discuss] Passing arguments to command in button.bind.
jkv
jkv at unixcluster.dk
Tue Jul 28 14:04:52 CEST 2009
Hi,
Im playing around with Tkinter and cant figure out how to pass arguments
to a def which are called when pressing a button.
When i bind to self.newdestination('whatever') the def is called (with
arguments) as soon as the button is drawn, whereas when i bind to
self.newdestination the function is called when i press the button - but
obviously without any arguments
Any hints?
---code---
class guiclass(object):
def __init__(self):
self.root = Tkinter.Tk()
self.root.title('MAIN WINDOW')
def config(self):
self.configwindow = Tkinter.Toplevel()
row = 0
optiondict = {}
#config_test.config.items('options') contains a dict from
configparser....
for option, value in config_test.config.items('options'):
#these two print statements are just for debugging...
print option
print value
Tkinter.Label(self.configwindow, text=str(option) + ': ',
anchor='w').grid(column=1, row=row, sticky='w')
Tkinter.Label(self.configwindow, text=str(value),
anchor='w').grid(column=2, row=row, sticky='w')
optiondict[option] = Tkinter.Button(self.configwindow,
text='Change destination')
optiondict[option].grid(column=3, row=row)
#When this button is pressed i want to pass a string to
newdestination....
optiondict[option].bind("<Button>",
self.newdestination('this is a string i want to pass'))
row = row + 1
self.configwindow.title('Configuration window')
def newdestination(self, test):
#print the string if passed...
print test
#bah = tkFileDialog.asksaveasfilename(parent=self.configwindow,
title='Choose savefile')
--- code ---
--
Regards,
jkv
http://unixcluster.dk/public.key
More information about the Tkinter-discuss
mailing list