Tkinter Callback question

Seo Sanghyeon unendliche at hanmail.net
Tue Aug 13 18:09:02 CEST 2002


Instead of:
> blah.add_command(command=callback(vlah))
Do this. Just put lambda in front of it.
> blah.add_command(command=lambda: callback(vlah))

Assuming you have nested_scoped Python, everything would walk fine.

----

>>> def write(word):
        print word

>>> import Tkinter
>>> root = Tkinter.Tk()

>>> button = Tkinter.Button(root, text='Push')
>>> button.configure(command=lambda: write(word)) # lambda!
>>> button.pack()

>>> word = 'xyzzy'
[Push] -> xyzzy

>>> word = 'plugh'
[Push] -> plugh



More information about the Python-list mailing list