Tkinter/Pmw callback question

Fredrik Lundh fredrik at pythonware.com
Sun Feb 25 17:40:15 EST 2001


David Lees write:
>     RunButton = Tkinter.Button(root, text = 'Run',command=foo)
>
> where foo has no arguments, but when I write:
>
>     RunButton = Tkinter.Button(root, text = 'Run',command=barf('junk'))
>
> things do not work correctly.  The 'barf' function seems to execute when
> the program starts up, but not when I click the Run button.
>
> What goes on here

in this statement:

    print barf("junk")

do you find it strange that the barf function is actually called
before the result is printed?

> what is the correct way to do call backs?

    def call_barf():
        barf("junk")
    RunButton = Tkinter.Button(root, text = 'Run',
        command=call_barf)

or

    RunButton = Tkinter.Button(root, text = 'Run',
        command=lambda: barf("junk"))

Cheers /F





More information about the Python-list mailing list