code1 ok
from Tkinter import *
from functools import partial
fields = 'Name', 'Job', 'Pay'
def fetch(entries,event):
for entry in entries:
print 'Input => "%s"' % entry.get()
print event
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=5, text=field)
ent = Entry(row)
row.pack(side=TOP, fill=X)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append(ent)
return entries
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', partial(fetch,ents))
root.mainloop()
code2 fail i don't understand why ?
from Tkinter import *
from functools import partial
fields = 'Name', 'Job', 'Pay'
def fetch(entries,event):
for entry in entries:
print 'Input => "%s"' % entry.get()
print event
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=5, text=field)
ent = Entry(row)
row.pack(side=TOP, fill=X)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append(ent)
return entries
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', partial(fetch,entries=ents))
root.mainloop()
code3: fail i know the reason
from Tkinter import *
from functools import partial
fields = 'Name', 'Job', 'Pay'
def fetch(event,entries):
for entry in entries:
print 'Input => "%s"' % entry.get()
print event
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=5, text=field)
ent = Entry(row)
row.pack(side=TOP, fill=X)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append(ent)
return entries
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', partial(fetch,ents))
root.mainloop()
code4: ok
from Tkinter import *
from functools import partial
fields = 'Name', 'Job', 'Pay'
def fetch(event,entries):
for entry in entries:
print 'Input => "%s"' % entry.get()
print event
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=5, text=field)
ent = Entry(row)
row.pack(side=TOP, fill=X)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append(ent)
return entries
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', partial(fetch,entries=ents))
root.mainloop()
there are four codes,code1,code4 it's ok,i know why;
code2,code3,it's not ok,i understand why code2 can't work,
would you mind to tell me why code3 can't work??
the output is:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
TypeError: fetch() got multiple values for keyword argument 'entries'
i don't understand it.
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss