473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

strange partial function aciton

code1 ok
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from functools import partial
  3. fields = 'Name', 'Job', 'Pay'
  4.  
  5. def fetch(entries,event):
  6.     for entry in entries:
  7.        print 'Input => "%s"' % entry.get()        
  8.     print  event
  9.  
  10.  
  11. def makeform(root, fields):
  12.     entries = []
  13.     for field in fields:
  14.         row = Frame(root)                          
  15.         lab = Label(row, width=5, text=field)      
  16.         ent = Entry(row)
  17.         row.pack(side=TOP, fill=X)                  
  18.         lab.pack(side=LEFT)
  19.         ent.pack(side=RIGHT, expand=YES, fill=X)    
  20.         entries.append(ent)
  21.     return entries
  22.  
  23.  
  24. if __name__ == '__main__':
  25.  
  26.     root = Tk()
  27.     ents = makeform(root, fields)
  28.     root.bind('<Return>', partial(fetch,ents))
  29.     root.mainloop() 
  30.  
code2 fail i don't understand why ?
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from functools import partial
  3. fields = 'Name', 'Job', 'Pay'
  4.  
  5. def fetch(entries,event):
  6.     for entry in entries:
  7.        print 'Input => "%s"' % entry.get()        
  8.     print  event
  9.  
  10.  
  11. def makeform(root, fields):
  12.     entries = []
  13.     for field in fields:
  14.         row = Frame(root)                          
  15.         lab = Label(row, width=5, text=field)      
  16.         ent = Entry(row)
  17.         row.pack(side=TOP, fill=X)                  
  18.         lab.pack(side=LEFT)
  19.         ent.pack(side=RIGHT, expand=YES, fill=X)    
  20.         entries.append(ent)
  21.     return entries
  22.  
  23.  
  24. if __name__ == '__main__':
  25.  
  26.     root = Tk()
  27.     ents = makeform(root, fields)
  28.     root.bind('<Return>', partial(fetch,entries=ents))
  29.     root.mainloop() 
  30.  
code3: fail i know the reason
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from functools import partial
  3. fields = 'Name', 'Job', 'Pay'
  4.  
  5. def fetch(event,entries):
  6.     for entry in entries:
  7.        print 'Input => "%s"' % entry.get()        
  8.     print  event
  9.  
  10.  
  11. def makeform(root, fields):
  12.     entries = []
  13.     for field in fields:
  14.         row = Frame(root)                          
  15.         lab = Label(row, width=5, text=field)      
  16.         ent = Entry(row)
  17.         row.pack(side=TOP, fill=X)                  
  18.         lab.pack(side=LEFT)
  19.         ent.pack(side=RIGHT, expand=YES, fill=X)    
  20.         entries.append(ent)
  21.     return entries
  22.  
  23.  
  24. if __name__ == '__main__':
  25.  
  26.     root = Tk()
  27.     ents = makeform(root, fields)
  28.     root.bind('<Return>', partial(fetch,ents))
  29.     root.mainloop() 
  30.  
code4: ok
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. from functools import partial
  3. fields = 'Name', 'Job', 'Pay'
  4.  
  5. def fetch(event,entries):
  6.     for entry in entries:
  7.        print 'Input => "%s"' % entry.get()        
  8.     print  event
  9.  
  10.  
  11. def makeform(root, fields):
  12.     entries = []
  13.     for field in fields:
  14.         row = Frame(root)                          
  15.         lab = Label(row, width=5, text=field)      
  16.         ent = Entry(row)
  17.         row.pack(side=TOP, fill=X)                  
  18.         lab.pack(side=LEFT)
  19.         ent.pack(side=RIGHT, expand=YES, fill=X)    
  20.         entries.append(ent)
  21.     return entries
  22.  
  23.  
  24. if __name__ == '__main__':
  25.  
  26.     root = Tk()
  27.     ents = makeform(root, fields)
  28.     root.bind('<Return>', partial(fetch,entries=ents))
  29.     root.mainloop() 
  30.  

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.
Aug 26 '11 #1
0 1165

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Michael Stembera | last post by:
Here is a very simple piece of code to repro this bug. template<typename T, int N> inline bool foo( void ) { return true; } template<typename T> inline bool foo<T, 1>( void ) { return...
6
by: Ronald Mai | last post by:
In my opinion, Ellipsis might be in the middle, not only in leftmost or rightmost, so a placeholder approach can be much more flexible and convenient. Here is a reference implementation: _ =...
2
by: tommydkat | last post by:
Hi! I'm updating a Windows application that we develop that uses a DB2 database. We switched from using Microsoft Developer Studio 6 to Visual Studio .Net 2003 to build our app and since that...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
8
by: laredotornado | last post by:
Hi, I want to pass my function myFunc('a', 'b', 'c') as an argument to another function. However, this will not work doStuff('x', 'y', myFunc('a', 'b', 'c'))
2
by: ale.beer | last post by:
hi everyone. i've notice that in all my pages there is a piece of j-s code that i've never write (i'm sure about that). i'm not so smart to understand what it does do, i suppose nothing, but if...
5
by: Matthew Wilson | last post by:
I wrote some code to create a user and update a user on a remote box by sending emails to that remote box. When I was done, I realized that my create_user function and my update_user function were...
12
by: aaragon | last post by:
I have this scenario: several arrays for which I have their fixed values at compilation time. Now, at runtime I need to access a specific array depending on an integer but I want to avoid if and...
7
by: jacklisp | last post by:
I have wrote a small function but got the error function: /*< squeeze */ void squeeze(char s1,char s2) { int de_s ; int i,j,k; for(i = 0;s2 !='\0';++i) {
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.