[Tkinter-discuss] lambda function to simplify

craf prog at vtr.net
Fri Dec 17 19:16:22 CET 2010


Hi.

According to this code....

------------------------------------------------------------------
import Tkinter


class App:
    def __init__(self, master):
        self.root = master
        self.b1 = Tkinter.Button(master)
        self.b1.pack()
        self.b1.bind('<Button-1>', lambda
e,widget=self:greeting(widget))
        self.root.protocol('WM_DELETE_WINDOW', lambda:((lambda e,
widget=self:greeting(widget))(self.root)))

def greeting(widget):
    widget.root.destroy()


master = Tkinter.Tk()
master.geometry('400x400')
app = App(master)
master.mainloop()
-------------------------------------------------------------------

I have access to the function (greeting) from the button and the window
close button.

It works fine, but wanted to know whether the use of lambda (lambda),
can be expressed in another way more elegant and less confusing.

Regards.

Cristian Abarzua



More information about the Tkinter-discuss mailing list