[Tkinter-discuss] lambada difficult to understand

守株待兔 1248283536 at qq.com
Mon Aug 22 03:53:27 CEST 2011

here is a example 9-18.pp3e\gui\tour\entry2.py   from  the book "programming python(third edition)",
i revise it as following,change the  "fetch(entries)" to "fetch(event,entries)" ,and add ,event.widget  
to understand lambda is my goal,
there is a question i can't solve,when i click button ,wrong output :
TypeError: <lambda>() takes exactly 1 argument (0 given)
would you kind to tell me how to revise it?
 command= (lambda event: fetch(event,ents))   #it is wrong ,but i don't know how to revise it?

from Tkinter import * 
from quitter import Quitter 
fields = 'Name', 'Job', 'Pay' 
def fetch(event,entries): 
    for entry in entries: 
        print 'Input => "%s"' % entry.get() ,event.widget        # get text 
def makeform(root, fields): 
    entries = [] 
    for field in fields: 
        row = Frame(root)                           # make a new row 
        lab = Label(row, width=5, text=field)       # add label, entry 
        ent = Entry(row) 
        row.pack(side=TOP, fill=X)                  # pack row on top 
        ent.pack(side=RIGHT, expand=YES, fill=X)    # grow horizontal 
    return entries 
if __name__ == '__main__': 
    root = Tk() 
    ents = makeform(root, fields) 
    root.bind('<Return>', (lambda event,entries=ents: fetch(event,ents)))    
    Button(root, text='Fetch',  
                 command= (lambda event: fetch(event,ents))).pack(side=LEFT) 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110822/e22b7af8/attachment.html>

More information about the Tkinter-discuss mailing list