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 
        lab.pack(side=LEFT) 
        ent.pack(side=RIGHT, expand=YES, fill=X)    # grow horizontal 
        entries.append(ent) 
    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) 
    Quitter(root).pack(side=RIGHT) 
    root.mainloop()
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to