Newbie Tkinter Question
John Grayson
johngrayson at home.com
Wed May 31 18:54:05 EDT 2000
Sure you can, just use a lambda expression. Here is
an example which shows an 'activate' callback (button
command) and a MB1 binding. Note that the binding
has to allow for the event object:
from Tkinter import *
def prtIt(text):
print text
root = Tk()
Button(root, text='B1',
command=lambda arg='Button 1': prtIt(arg)).pack(side=LEFT)
b2 = Button(root, text='B2')
b2.pack(side=LEFT)
b2.bind('<Button-1>', lambda e,arg='Button 2': prtIt(arg))
root.mainloop()
John Grayson
Dean wrote:
>
> Is it possible to pass arguments to a callback in Python/Tkinter? I know
> this can be done in Perl, but after reviewing the documentation, it's not
> clear to me that you can pass any arguments ( except the event object ) to a
> callback function bound to an event. Any help would be greatly appreciated!
>
> Dean
More information about the Python-list
mailing list