Tkinter idioms (was: Some basic questions about Tkinter (probably v easy for experts!))

John Grayson johngrayson at home.com
Sat Feb 10 19:01:38 EST 2001


In article
<50B7C024B0AA609B.8CB8E2F63E2849E7.2783498FE2A00925 at lp.airnews.net>,
  claird at starbase.neosoft.com (Cameron Laird) wrote:
> In article <ADBg6.13592$AH6.2042423 at newsc.telia.net>,
> Fredrik Lundh <fredrik at effbot.org> wrote:
>
	.
>
	.
>
	.
> >not directly -- there's something called lambdas (in Python, not
> >in Tkinter), but it's usually better to use a plain function:
> >
> >    def myfunc():
> >        otherfunc(1, 2, 3)
> >
> >    b = Button(master, command=myfunc)
> >
> >Cheers /F
> >
> >
>
> Tell me if this is pertinent--I find myself writing a
> lot of formulaic lambdas in my Tkinter compositions.
> Example:  a Button command has a no-arg signature, but
> when I want to gang some other binding to the same com-
> mand, I have to write a trivial lambda to ignore the
> supplied event.  Is there something I'm missing?
> --
>
> Cameron Laird <claird at NeoSoft.com>
> Business:  http://www.Phaseit.net
> Personal:  http://starbase.neosoft.com/~claird/home.html
>

It is a common practice to put a default arg as the first
argument of a function, then you can call the function
from an event or a command:

def buttonAction(e=None):
    ....

or:

    def buttonAction(self, e=None):
        ....


(Page 106 PTkP)

    John


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list