From 1248283536 at qq.com Tue Aug 9 15:18:26 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Tue, 9 Aug 2011 21:18:26 +0800 Subject: [Tkinter-discuss] why tkinter do not quit? Message-ID: here is my program: from Tkinter import * def helloButton(): print 'hello button' root.quit root = Tk() Button(root,text = 'Hello Button',command = helloButton).pack() root.mainloop() when i click on my button,print is ok,why root.quit have no effect? -------------- next part -------------- An HTML attachment was scrubbed... URL: From igor.e.novikov at gmail.com Tue Aug 9 15:50:00 2011 From: igor.e.novikov at gmail.com (Igor Novikov) Date: Tue, 9 Aug 2011 16:50:00 +0300 Subject: [Tkinter-discuss] why tkinter do not quit? In-Reply-To: References: Message-ID: Hi, root.quit is a reference to object field but not a quit() method. Try using root.quit() This should resolve an issue. -- Regards, Igor Novikov sK1 Project http://sk1project.org 2011/8/9 ???? <1248283536 at qq.com> > here is my program: > from Tkinter import * > def helloButton(): > print 'hello button' > root.quit > root = Tk() > Button(root,text = 'Hello Button',command = helloButton).pack() > root.mainloop() > > when i click on my button,print is ok,why root.quit have no effect? > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From 1248283536 at qq.com Tue Aug 9 16:00:46 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Tue, 9 Aug 2011 22:00:46 +0800 Subject: [Tkinter-discuss] =?gbk?b?u9i4tKO6ICB3aHkgdGtpbnRlciBkbyBub3Qg?= =?gbk?q?quit=3F?= Message-ID: it's so strage for me to understand code1 import Tkinter top=Tkinter.Tk() button=Tkinter.Button(top,text = 'Hello Button',command = top.quit) button.pack() top.mainloop() code1 can run ,when you click button ,it will quit code2 import Tkinter top=Tkinter.Tk() button=Tkinter.Button(top,text = 'Hello Button',command = top.quit()) button.pack() top.mainloop() code2 can run too ,but when you click button,it will not quit. what is the difference between quit and quit() ?? ------------------ ???? ------------------ ???: "Igor Novikov"; ????: 2011?8?9?(???) ??9:50 ???: "????"<1248283536 at qq.com>; ??: "Tkinter-discuss"; ??: Re: [Tkinter-discuss] why tkinter do not quit? Hi, root.quit is a reference to object field but not a quit() method. Try using root.quit() This should resolve an issue. -- Regards, Igor Novikov sK1 Project http://sk1project.org 2011/8/9 ???? <1248283536 at qq.com> here is my program: from Tkinter import * def helloButton(): print 'hello button' root.quit root = Tk() Button(root,text = 'Hello Button',command = helloButton).pack() root.mainloop() when i click on my button,print is ok,why root.quit have no effect? _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: From igor.e.novikov at gmail.com Tue Aug 9 16:20:36 2011 From: igor.e.novikov at gmail.com (Igor Novikov) Date: Tue, 9 Aug 2011 17:20:36 +0300 Subject: [Tkinter-discuss] =?gb2312?b?u9i4tKO6ICB3aHkgdGtpbnRlciBkbyBub3Qg?= =?gb2312?b?cXVpdD8=?= In-Reply-To: References: Message-ID: 2011/8/9 ???? <1248283536 at qq.com> > > > what is the difference between quit and quit() ?? > *quit* is a reference to callable but *quit()* is a method call. The code *command = top.quit *just passes a callable reference, but *command = top.quit()* passes result of *top.quit()* execution. Possibly exception could be raised in last case. -- Regards, Igor Novikov sK1 Project http://sk1project.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From 1248283536 at qq.com Wed Aug 10 05:14:57 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Wed, 10 Aug 2011 11:14:57 +0800 Subject: [Tkinter-discuss] =?gbk?b?u9i4tKO6ILvYuLSjuiAgd2h5IHRraW50ZXIg?= =?gbk?q?do_not_quit=3F?= Message-ID: i am sitll confused,please see the following >>> def abc(): ... print "i am abc" ... return "i am not abc" ... >>> abc >>> abc() i am abc 'i am not abc' >>> code1 import Tkinter def abc(): print "i am abc" return "i am not abc" top=Tkinter.Tk() button=Tkinter.Button(top,text = 'Hello Button',command =abc) button.pack() top.mainloop() when you click button ,the output is : i am abc my question is :where is the "i am not abc"?? code2 import Tkinter def abc(): print "i am abc" return "i am not abc" top=Tkinter.Tk() button=Tkinter.Button(top,text = 'Hello Button',command =abc()) button.pack() top.mainloop() when code2 run ,there is output "i am abc",(where is "i am not abc")? when you click button ,there is no reaction, why? ------------------ ???? ------------------ ???: "Igor Novikov"; ????: 2011?8?9?(???) ??10:20 ???: "????"<1248283536 at qq.com>; ??: "Tkinter-discuss"; ??: Re: ??? [Tkinter-discuss] why tkinter do not quit? 2011/8/9 ???? <1248283536 at qq.com> what is the difference between quit and quit() ?? quit is a reference to callable but quit() is a method call. The code command = top.quit just passes a callable reference, but command = top.quit() passes result of top.quit() execution. Possibly exception could be raised in last case. -- Regards, Igor Novikov sK1 Project http://sk1project.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Wed Aug 10 06:10:50 2011 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 10 Aug 2011 00:10:50 -0400 Subject: [Tkinter-discuss] =?iso-8859-1?q?=BB=D8=B8=B4=A3=BA_=BB=D8=B8=B4?= =?iso-8859-1?q?=A3=BA__why_tkinter_do_not_quit=3F?= In-Reply-To: References: Message-ID: <4E4204CA.50906@codebykevin.com> On 8/9/11 11:14 PM, ???????? wrote: > when code2 run ,there is output "i am abc",(where is "i am not abc")? print "i am abc" displays the string "i am abc" in standard output. return "i am not abc" is the return value of the function--it is not displayed. You'd have to use the "print" command for that. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From bob at mellowood.ca Wed Aug 10 18:13:29 2011 From: bob at mellowood.ca (Bob van der Poel) Date: Wed, 10 Aug 2011 09:13:29 -0700 Subject: [Tkinter-discuss] =?gb2312?b?u9i4tKO6ILvYuLSjuiB3aHkgdGtpbnRlciBk?= =?gb2312?b?byBub3QgcXVpdD8=?= In-Reply-To: References: Message-ID: 2011/8/9 ???? <1248283536 at qq.com>: > i am sitll confused,please see the following >>>> def abc(): > ... print "i am abc" > ... return "i am not abc" > ... >>>> abc > >>>> abc() > i am abc > 'i am not abc' >>>> > code1 > > import Tkinter > def abc(): > print "i am abc" > return "i am not abc" > top=Tkinter.Tk() > button=Tkinter.Button(top,text = 'Hello Button',command =abc) > button.pack() > top.mainloop() > > when you click button ,the output is : > i am abc > my question is :where is the "i am not abc"?? When a function is called as a callback there is no return value. If you want a value from a callback you need to have the callback save it "somewhere". > code2 > import Tkinter > def abc(): > print "i am abc" > return "i am not abc" > top=Tkinter.Tk() > button=Tkinter.Button(top,text = 'Hello Button',command =abc()) > button.pack() > top.mainloop() > > when code2 run ,there is output "i am abc",(where is "i am not abc")? > > when you click button ,there is no reaction, why? > > > > > ------------------ ???? ------------------ > ???: "Igor Novikov"; > ????: 2011?8?9?(???) ??10:20 > ???: "????"<1248283536 at qq.com>; > ??: "Tkinter-discuss"; > ??: Re: ??? [Tkinter-discuss] why tkinter do not quit? > > > 2011/8/9 ???? <1248283536 at qq.com> >> >> >> what is the difference between quit and quit() ?? > > quit is a reference to callable but quit() is a method call. > The code command = top.quit just passes a callable reference, > but command = top.quit() passes result of top.quit() execution. > Possibly exception could be raised in last case. > > -- > Regards, > > Igor Novikov > sK1 Project > http://sk1project.org > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- **** Listen to my CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From alan.gauld at btinternet.com Fri Aug 12 01:56:39 2011 From: alan.gauld at btinternet.com (Alan Gauld) Date: Fri, 12 Aug 2011 00:56:39 +0100 Subject: [Tkinter-discuss] =?utf-8?b?5Zue5aSN77yaIOWbnuWkje+8miAgd2h5IHRr?= =?utf-8?q?inter_do_not_quit=3F?= In-Reply-To: References: Message-ID: <4E446C37.2000105@btinternet.com> On 10/08/11 04:14, ???? wrote: > i am sitll confused,please see the following > >>> def abc(): > ... print "i am abc" > ... return "i am not abc" > ... > >>> abc > > >>> abc() > i am abc > 'i am not abc' The first line is the print statement in the function. The second line is the return value of the function. The interpreter always displays the value of any expression you type Wen you run the function in the script the return value is not displayed, and since Tkinter does not store the return value of an action it just gets lost. > when you click button ,the output is : > i am abc > my question is :where is the "i am not abc"?? Lost in the garbage inside Tkinter. > button=Tkinter.Button(top,text = 'Hello Button',command =abc()) > button.pack() > top.mainloop() > > when code2 run ,there is output "i am abc",(where is "i am not abc")? > > when you click button ,there is no reaction, why? The parentheses after abc() say to Python to execute the function. So you have assigned the return value of your function to the button's command. So the command stores 'i am not abc' - a string. But the button cannot execute the string so when you click it nothing happens. HTH, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ From alan.gauld at btinternet.com Fri Aug 12 01:56:39 2011 From: alan.gauld at btinternet.com (Alan Gauld) Date: Fri, 12 Aug 2011 00:56:39 +0100 Subject: [Tkinter-discuss] =?utf-8?b?5Zue5aSN77yaIOWbnuWkje+8miAgd2h5IHRr?= =?utf-8?q?inter_do_not_quit=3F?= In-Reply-To: References: Message-ID: <4E446C37.2000105@btinternet.com> On 10/08/11 04:14, ???? wrote: > i am sitll confused,please see the following > >>> def abc(): > ... print "i am abc" > ... return "i am not abc" > ... > >>> abc > > >>> abc() > i am abc > 'i am not abc' The first line is the print statement in the function. The second line is the return value of the function. The interpreter always displays the value of any expression you type Wen you run the function in the script the return value is not displayed, and since Tkinter does not store the return value of an action it just gets lost. > when you click button ,the output is : > i am abc > my question is :where is the "i am not abc"?? Lost in the garbage inside Tkinter. > button=Tkinter.Button(top,text = 'Hello Button',command =abc()) > button.pack() > top.mainloop() > > when code2 run ,there is output "i am abc",(where is "i am not abc")? > > when you click button ,there is no reaction, why? The parentheses after abc() say to Python to execute the function. So you have assigned the return value of your function to the button's command. So the command stores 'i am not abc' - a string. But the button cannot execute the string so when you click it nothing happens. HTH, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ From 1248283536 at qq.com Fri Aug 12 15:32:28 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Fri, 12 Aug 2011 21:32:28 +0800 Subject: [Tkinter-discuss] pixels and plot Message-ID: in my computer ,xrandr: Screen 0: minimum 320 x 200, current 1280 x 800, maximum 8192 x 8192 i want to konw how can matplotlab draw (x,y) which has 2000 pairs or more (x,y) data?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From 1248283536 at qq.com Wed Aug 17 04:41:52 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Wed, 17 Aug 2011 10:41:52 +0800 Subject: [Tkinter-discuss] bind between event and callback Message-ID: code1 from Tkinter import * root = Tk() def callback(event): print "i am here" frame = Frame(root, width=100, height=100) frame.bind("", callback) frame.pack() root.mainloop() when i press "enter",there is no output "i am here" code2 from Tkinter import * root = Tk() def callback(event): print "i am here" frame = Frame(root, width=100, height=100) frame.bind("", callback) frame.pack() root.mainloop() when i press any key ,there is no output "i am here" -------------- next part -------------- An HTML attachment was scrubbed... URL: From ozgulfirat at gmail.com Wed Aug 17 07:47:56 2011 From: ozgulfirat at gmail.com (Firat Ozgul) Date: Wed, 17 Aug 2011 08:47:56 +0300 Subject: [Tkinter-discuss] bind between event and callback In-Reply-To: References: Message-ID: The reason why you get no response is the lack of focus when you first create the frame. Therefore you should set the focus on frame manually, like this: [code] from Tkinter import * root = Tk() def callback(event): print "i am here" frame = Frame(root, width=100, height=100) frame.bind("", callback) frame.focus_set() frame.pack() root.mainloop() [/code] 2011/8/17 ???? <1248283536 at qq.com>: > code1 > from Tkinter import * > root = Tk() > def callback(event): > ??? print "i am here" > > frame = Frame(root, width=100, height=100) > frame.bind("", callback) > frame.pack() > root.mainloop() > > when? i press? "enter",there is no output? "i am here" > code2 > from Tkinter import * > root = Tk() > def callback(event): > ??? print "i am here" > > frame = Frame(root, width=100, height=100) > frame.bind("", callback) > frame.pack() > root.mainloop() > > when? i press? any key ,there is no output? "i am here" > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From 1248283536 at qq.com Wed Aug 17 11:06:28 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Wed, 17 Aug 2011 17:06:28 +0800 Subject: [Tkinter-discuss] =?gbk?b?u9i4tKO6ICBiaW5kIGJldHdlZW4gZXZlbnQg?= =?gbk?q?and_callback?= Message-ID: why in the following code,there is no "frame.focus_set()" in the code ,it can run ,why?? from Tkinter import * root = Tk() def callback(event): print "i am here" frame = Frame(root, width=100, height=100) frame.bind("", callback) frame.pack() root.mainloop() ------------------ ???? ------------------ ???: "Firat Ozgul"; ????: 2011?8?17?(???) ??1:46 ???: "????"<1248283536 at qq.com>; ??: Re: [Tkinter-discuss] bind between event and callback The reason why you get no response is the lack of focus when you first create the frame. Therefore you should set the focus on frame manually, like this: [code] from Tkinter import * root = Tk() def callback(event): print "i am here" frame = Frame(root, width=100, height=100) frame.bind("", callback) frame.focus_set() frame.pack() root.mainloop() [/code] 2011/8/17 ???? <1248283536 at qq.com>: > code1 > from Tkinter import * > root = Tk() > def callback(event): > print "i am here" > > frame = Frame(root, width=100, height=100) > frame.bind("", callback) > frame.pack() > root.mainloop() > > when i press "enter",there is no output "i am here" > code2 > from Tkinter import * > root = Tk() > def callback(event): > print "i am here" > > frame = Frame(root, width=100, height=100) > frame.bind("", callback) > frame.pack() > root.mainloop() > > when i press any key ,there is no output "i am here" > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Wed Aug 17 11:26:39 2011 From: klappnase at web.de (Michael Lange) Date: Wed, 17 Aug 2011 11:26:39 +0200 Subject: [Tkinter-discuss] =?utf-8?b?5Zue5aSN77yaIGJpbmQgYmV0d2VlbiBldmVu?= =?utf-8?q?t_and_callback?= In-Reply-To: References: Message-ID: <20110817112639.d7467198.klappnase@web.de> Hi, Thus spoketh "????" <1248283536 at qq.com> unto us on Wed, 17 Aug 2011 17:06:28 +0800: > why in the following code,there is no "frame.focus_set()" in the > code ,it can run ,why?? from Tkinter import * > root = Tk() > def callback(event): > print "i am here" > > frame = Frame(root, width=100, height=100) > frame.bind("", callback) > frame.pack() > root.mainloop() Mouse events are handled differently than key events. When you click somewhere in the window of course the window manager "knows" which widget is clicked - the one under the mouse pointer's "hot spot". But when you press some key on your keyboard - how would the window manager "know" which window and which of its child widgets "is meant"? That is where the "keyboard focus" comes in. Keyboard events are always sent (by the window manager) to the window that has focus, where "window" does not only mean a main application window like your Tk() instannce, but also "child windows" as your Tkinter.Frame() . I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. All your people must learn before you can reach for the stars. -- Kirk, "The Gamesters of Triskelion", stardate 3259.2 From 1248283536 at qq.com Wed Aug 17 15:53:47 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Wed, 17 Aug 2011 21:53:47 +0800 Subject: [Tkinter-discuss] =?gbk?b?u9i4tKO6ILvYuLSjuiBiaW5kIGJldHdlZW4g?= =?gbk?q?event_and_callback?= Message-ID: code1 from Tkinter import * root = Tk() def callback(event): print "i am here" frame = Frame(root, width=100, height=100) frame.bind("", callback) frame.focus_set() frame.pack() root.mainloop() code2 from Tkinter import * root = Tk() def callback(event): print "i am here" frame = Frame(root, width=100, height=100) frame.focus_set() frame.bind("", callback) frame.pack() root.mainloop() code1,code2 all can run ,i want to know which one is better? is it reasonable that frame.focus_set() is before frame.bind("", callback) or after it?? ------------------ ???? ------------------ ???: "Michael Lange"; ????: 2011?8?17?(???) ??5:26 ???: "tkinter-discuss"; ??: Re: [Tkinter-discuss]??? bind between event and callback Hi, Thus spoketh "????" <1248283536 at qq.com> unto us on Wed, 17 Aug 2011 17:06:28 +0800: > why in the following code,there is no "frame.focus_set()" in the > code ,it can run ,why?? from Tkinter import * > root = Tk() > def callback(event): > print "i am here" > > frame = Frame(root, width=100, height=100) > frame.bind("", callback) > frame.pack() > root.mainloop() Mouse events are handled differently than key events. When you click somewhere in the window of course the window manager "knows" which widget is clicked - the one under the mouse pointer's "hot spot". But when you press some key on your keyboard - how would the window manager "know" which window and which of its child widgets "is meant"? That is where the "keyboard focus" comes in. Keyboard events are always sent (by the window manager) to the window that has focus, where "window" does not only mean a main application window like your Tk() instannce, but also "child windows" as your Tkinter.Frame() . I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. All your people must learn before you can reach for the stars. -- Kirk, "The Gamesters of Triskelion", stardate 3259.2 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: From ozgulfirat at gmail.com Wed Aug 17 19:17:10 2011 From: ozgulfirat at gmail.com (Firat Ozgul) Date: Wed, 17 Aug 2011 20:17:10 +0300 Subject: [Tkinter-discuss] =?gb2312?b?u9i4tKO6ILvYuLSjuiBiaW5kIGJldHdlZW4g?= =?gb2312?b?ZXZlbnQgYW5kIGNhbGxiYWNr?= In-Reply-To: References: Message-ID: I think there is no difference. Both positions seem reasonable to me. So you can insert the set_focus line at whichever position you wish. 2011/8/17 ???? <1248283536 at qq.com>: > code1 > from Tkinter import * > root = Tk() > def callback(event): > print "i am here" > > frame = Frame(root, width=100, height=100) > > frame.bind("", callback) > frame.focus_set() > frame.pack() > root.mainloop() > > code2 > from Tkinter import * > root = Tk() > def callback(event): > print "i am here" > > frame = Frame(root, width=100, height=100) > frame.focus_set() > frame.bind("", callback) > > frame.pack() > root.mainloop() > > code1,code2 all can run ,i want to know which one is better? > is it reasonable that frame.focus_set() is before frame.bind("", > callback) or after it?? > ------------------ ???? ------------------ > ???: "Michael Lange"; > ????: 2011?8?17?(???) ??5:26 > ???: "tkinter-discuss"; > ??: Re: [Tkinter-discuss]??? bind between event and callback > > Hi, > > Thus spoketh "????" <1248283536 at qq.com> > unto us on Wed, 17 Aug 2011 17:06:28 +0800: > >> why in the following code,there is no "frame.focus_set()" in the >> code ,it can run ,why?? from Tkinter import * >> root = Tk() >> def callback(event): >> print "i am here" >> >> frame = Frame(root, width=100, height=100) >> frame.bind("", callback) >> frame.pack() >> root.mainloop() > > Mouse events are handled differently than key events. > When you click somewhere in the window of course the window manager > "knows" which widget is clicked - the one under the mouse pointer's "hot > spot". But when you press some key on your keyboard - how would the window > manager "know" which window and which of its child widgets "is meant"? > That is where the "keyboard focus" comes in. Keyboard events are always > sent (by the window manager) to the window that has focus, where > "window" does not only mean a main application window like your Tk() > instannce, but also "child windows" as your Tkinter.Frame() . > > I hope this helps > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > All your people must learn before you can reach for the stars. > -- Kirk, "The Gamesters of Triskelion", stardate 3259.2 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From 1248283536 at qq.com Thu Aug 18 06:09:52 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Thu, 18 Aug 2011 12:09:52 +0800 Subject: [Tkinter-discuss] and or ?? Message-ID: there is a code: #coding:utf-8 from Tkinter import * from sys import stdout, exit # lambda generates a function widget = Button(None, # but contains just an expression text='Hello event world', command=(lambda: stdout.write('Hello lambda world\n') or exit()) ) widget.pack() widget.mainloop() when you click the button,there is output : Hello lambda world, then exit the program. i am confused, why not use "and" ? i made a try, if i use "or",the program will not exit ,why? -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Thu Aug 18 11:54:10 2011 From: klappnase at web.de (Michael Lange) Date: Thu, 18 Aug 2011 11:54:10 +0200 Subject: [Tkinter-discuss] and or ?? In-Reply-To: References: Message-ID: <20110818115410.0867337a.klappnase@web.de> Hi, Thus spoketh "????" <1248283536 at qq.com> unto us on Thu, 18 Aug 2011 12:09:52 +0800: > there is a code: > #coding:utf-8 > from Tkinter import * > from sys import stdout, exit # lambda generates a > function > widget = Button(None, # but contains just an > expression text='Hello event world', > command=(lambda: stdout.write('Hello lambda world\n') or > exit()) ) > widget.pack() > widget.mainloop() > > when you click the button,there is output : Hello lambda world, then > exit the program. i am confused, why not use "and" ? i made a try, if > i use "or",the program will not exit ,why? You seem to expect that the "and" inside the body of your lamdba function will force the interpreter to execute first the stdout.write() command "and" then the exit() command. Actually however using "and" or "or" in your lambda will cause the whole expression to be evaluated as True or False. Now what happens is: First case: stdout.write('Hello lambda world\n') and exit() This evaluates to True if *both* parts are True. So the interpreter first evaluates stdout.write('Hello lambda world\n') . The return value of this call is "None" which evaluates to False so the whole expression will evaluate to False, no matter what the second part does - the interpreter will not even try. Second case: stdout.write('Hello lambda world\n') or exit() This evaluates to True if *one or both* parts are True. Now again the interpreter tries stdout.write() first, gets a "False" and so tries to check the result of the second statement. Unfortunately it never gets to see the result, because exit() stops the interpreter ;) Maybe this behavior is easier to understand if you try something like this at a python prompt: >>> from sys import stdout >>> print stdout.write('foo\n') foo None >>> print stdout.write('foo\n') or stdout.write('bar\n') foo bar None >>> print stdout.write('foo\n') and stdout.write('bar\n') foo None >>> if stdout.write('foo\n'): ... print 'True' ... else: ... print 'False' ... foo False >>> I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. There's no honorable way to kill, no gentle way to destroy. There is nothing good in war. Except its ending. -- Abraham Lincoln, "The Savage Curtain", stardate 5906.5 From 1248283536 at qq.com Sat Aug 20 05:18:22 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sat, 20 Aug 2011 11:18:22 +0800 Subject: [Tkinter-discuss] mainloop() problem Message-ID: in many cases,you can use mainloop() or widget.mainloop(),such as: from Tkinter import * widget = Button(text='Spam', padx=10, pady=10) widget.pack(padx=20, pady=20) widget.config(cursor='gumby') widget.config(bd=8, relief=RAISED) widget.config(bg='dark green', fg='white') widget.config(font=('helvetica', 20, 'underline italic')) widget.mainloop() # mainloop() is ok i don't know why i can't use mainloop() instead of Demo().mainloop()?? from Tkinter import * # get base widget set from dialogTable import demos # button callback handlers from quitter import Quitter # attach a quit object to me class Demo(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Label(self, text="Basic demos").pack() for (key, value) in demos.items(): Button(self, text=key, command=value).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH) if __name__ == '__main__': Demo().mainloop() # you can't use mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Sat Aug 20 11:10:06 2011 From: klappnase at web.de (Michael Lange) Date: Sat, 20 Aug 2011 11:10:06 +0200 Subject: [Tkinter-discuss] mainloop() problem In-Reply-To: References: Message-ID: <20110820111006.d2e3eb03.klappnase@web.de> Hi, Thus spoketh "????" <1248283536 at qq.com> unto us on Sat, 20 Aug 2011 11:18:22 +0800: (...) > i don't know why i can't use mainloop() instead of Demo().mainloop > ()?? > > from Tkinter import * # get base widget set > from dialogTable import demos # button callback handlers > from quitter import Quitter # attach a quit object to me > > class Demo(Frame): > def __init__(self, parent=None): > Frame.__init__(self, parent) > self.pack() > Label(self, text="Basic demos").pack() > for (key, value) in demos.items(): > Button(self, text=key, command=value).pack(side=TOP, > fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH) > > if __name__ == '__main__': > Demo().mainloop() # you can't use mainloop() If you look at the error message you get when you try to call mainloop() you will find valuable information: Traceback (most recent call last): File "test7.py", line 16, in mainloop() # you can't use mainloop() File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 328, in mainloop _default_root.tk.mainloop(n) AttributeError: 'NoneType' object has no attribute 'tk' So let's have a look at the Tkinter.mainloop() function: def mainloop(n=0): """Run the main loop of Tcl.""" _default_root.tk.mainloop(n) To understand this, you need to know that Tkinter._default_root is an internally used placeholder for the application's Tk() instance. Initially _default_root is set to None, though. So effectively Tkinter.mainloop () is just a shortcut to the Tk () window's (or any other tk widget's) mainloop() method. Considering this, it is easy to see why the call to mainloop() in your example fails: you call mainloop() before any widget has been created and so there is no _default_root yet. I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. I realize that command does have its fascination, even under circumstances such as these, but I neither enjoy the idea of command nor am I frightened of it. It simply exists, and I will do whatever logically needs to be done. -- Spock, "The Galileo Seven", stardate 2812.7 From 1248283536 at qq.com Sun Aug 21 07:57:21 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sun, 21 Aug 2011 13:57:21 +0800 Subject: [Tkinter-discuss] what is the meanning of triple? Message-ID: here is the code: from Tkinter import * from tkColorChooser import askcolor def setBgColor(): (triple, hexstr) = askcolor() if hexstr: print hexstr push.config(bg=hexstr) root = Tk() push = Button(root, text='Set Background Color', command=setBgColor) push.config(height=3, font=('times', 20, 'bold')) push.pack(expand=YES, fill=BOTH) root.mainloop() in the (triple, hexstr) = askcolor(), i want to know the meaning of triple?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Sun Aug 21 10:40:49 2011 From: klappnase at web.de (Michael Lange) Date: Sun, 21 Aug 2011 10:40:49 +0200 Subject: [Tkinter-discuss] what is the meanning of triple? In-Reply-To: References: Message-ID: <20110821104049.52bcdf92.klappnase@web.de> Thus spoketh "????" <1248283536 at qq.com> unto us on Sun, 21 Aug 2011 13:57:21 +0800: > (triple, hexstr) = askcolor() .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. We Klingons believe as you do -- the sick should die. Only the strong should live. -- Kras, "Friday's Child", stardate 3497.2 From klappnase at web.de Sun Aug 21 10:59:37 2011 From: klappnase at web.de (Michael Lange) Date: Sun, 21 Aug 2011 10:59:37 +0200 Subject: [Tkinter-discuss] what is the meanning of triple? In-Reply-To: <20110821104049.52bcdf92.klappnase@web.de> References: <20110821104049.52bcdf92.klappnase@web.de> Message-ID: <20110821105937.d5dd8298.klappnase@web.de> Hi, oops, I accidentally hit the "Send" button :( > Thus spoketh "????" <1248283536 at qq.com> > unto us on Sun, 21 Aug 2011 13:57:21 +0800: > > > (triple, hexstr) = askcolor() As you have probably noticed the return value of askcolor() is something like: >>> askcolor() ((214, 215, 214), '#d6d7d6') where the second part is the original color string as returned by tk_chooseColor , the first part, the 3-tuple, was apparently brought to us by Frederik Lundh, who wrote the tkColorChooser module. The magic lines from tkColorChooser.py are: # to simplify application code, the color chooser returns # an RGB tuple together with the Tk color string r, g, b = widget.winfo_rgb(result) return (r/256, g/256, b/256), str(result) so you see, the triple is simply a tuple of (red, green, blue) color values, ranging from 0 - 255 . I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Only a fool fights in a burning house. -- Kank the Klingon, "Day of the Dove", stardate unknown From Cameron at phaseit.net Sun Aug 21 21:22:52 2011 From: Cameron at phaseit.net (Cameron Laird) Date: Sun, 21 Aug 2011 19:22:52 +0000 Subject: [Tkinter-discuss] what is the meanning of triple? In-Reply-To: References: Message-ID: <20110821192252.GA11554@lairds.us> On Sun, Aug 21, 2011 at 01:57:21PM +0800, ???? wrote: . . . > here is the code: > from Tkinter import * > from tkColorChooser import askcolor > > def setBgColor(): > (triple, hexstr) = askcolor() > if hexstr: > print hexstr > push.config(bg=hexstr) > > root = Tk() > push = Button(root, text='Set Background Color', command=setBgColor) > push.config(height=3, font=('times', 20, 'bold')) > push.pack(expand=YES, fill=BOTH) > root.mainloop() > > in the (triple, hexstr) = askcolor(), i want to know the meaning of triple?? . . . Your question surprises me a bit; it makes me think that you would benefit from more practice with Python basics, and that you're "working too hard". At one level, the answer is, "'triple' is a color triple, that is, a 3-tuple of integers from the range 0-255." Here's another way to approach the answer: launch an interactive shell, that is, type "python" at the shell prompt in Linux, MacOS, ..., or click on ActiveState Python for Windows, or ... This is an important step. Your progress in Python (let alone Tkinter) will be much, MUCH faster once you have comfort and familiarity with the interactive shell. At Python's prompt, enter two lines: >>> import tkColorChooser >>> tkColorChooser.askcolor() Soon a new window, one with a "color wheel", will pop up. Click on a color. Select "OK". Back at the Python prompt, you'll see something like ((90, 255, 140), '#5aff8c') The "(90, 255, 140)" part is triple. I don't know what you intend by "the meaning of triple", but what I've written above surely gets you closer to it. I strongly urge you, again, to practice Python basics. From Cameron at phaseit.net Sun Aug 21 21:30:20 2011 From: Cameron at phaseit.net (Cameron Laird) Date: Sun, 21 Aug 2011 19:30:20 +0000 Subject: [Tkinter-discuss] what is the meanning of triple? In-Reply-To: <20110821192252.GA11554@lairds.us> References: <20110821192252.GA11554@lairds.us> Message-ID: <20110821193020.GB11554@lairds.us> On Sun, Aug 21, 2011 at 07:22:52PM +0000, Cameron Laird wrote: > . > . > . > > here is the code: > > from Tkinter import * > > from tkColorChooser import askcolor > > > > def setBgColor(): > > (triple, hexstr) = askcolor() > > if hexstr: > > print hexstr > > push.config(bg=hexstr) > > > > root = Tk() > > push = Button(root, text='Set Background Color', command=setBgColor) > > push.config(height=3, font=('times', 20, 'bold')) > > push.pack(expand=YES, fill=BOTH) > > root.mainloop() > > > > in the (triple, hexstr) = askcolor(), i want to know the meaning of triple?? > . > . > . > Your question surprises me a bit; it makes me think > that you would benefit from more practice with Python > basics, and that you're "working too hard". > > At one level, the answer is, "'triple' is a color > triple, that is, a 3-tuple of integers from the range > 0-255." > > Here's another way to approach the answer: launch an > interactive shell, that is, type "python" at the shell > prompt in Linux, MacOS, ..., or click on ActiveState > Python for Windows, or ... This is an important step. > Your progress in Python (let alone Tkinter) will be > much, MUCH faster once you have comfort and familiarity > with the interactive shell. > > At Python's prompt, enter two lines: > >>> import tkColorChooser > >>> tkColorChooser.askcolor() > Soon a new window, one with a "color wheel", will pop > up. Click on a color. Select "OK". Back at the Python > prompt, you'll see something like > > ((90, 255, 140), '#5aff8c') > > The "(90, 255, 140)" part is triple. > > I don't know what you intend by "the meaning of triple", > but what I've written above surely gets you closer to it. > I strongly urge you, again, to practice Python basics. . . . It occurs to me that you might not realize how to "reduce" programs, so that you can write, and run, import tkColorChooser print tkColorChooser.askcolor() as a "batch" program, for yourself. Perhaps you also don't know to look up or or ... From kevin.buchs at gmail.com Sun Aug 21 23:59:07 2011 From: kevin.buchs at gmail.com (Kevin Buchs) Date: Sun, 21 Aug 2011 16:59:07 -0500 Subject: [Tkinter-discuss] what is the meanning of triple? In-Reply-To: References: Message-ID: It is the tuple of three integers representing the RGB (red,green,blue) intensities making up the chosen color. 255 is maximum, usually, with 32-bit color. The hexstring is another way to write the same set of three values. - Kevin 2011/8/21 ???? <1248283536 at qq.com> > in the (triple, hexstr) = askcolor(), i want to know the meaning of > triple?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From 1248283536 at qq.com Mon Aug 22 03:53:27 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Mon, 22 Aug 2011 09:53:27 +0800 Subject: [Tkinter-discuss] lambada difficult to understand Message-ID: 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: () 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('', (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() -------------- next part -------------- An HTML attachment was scrubbed... URL: From 1248283536 at qq.com Mon Aug 22 07:59:45 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Mon, 22 Aug 2011 13:59:45 +0800 Subject: [Tkinter-discuss] No module named tkMessageBox in python3.2?? Message-ID: python3.2 Python 3.2 (r32:88445, Mar 25 2011, 19:28:28) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from tkMessageBox import askokcancel Traceback (most recent call last): File "", line 1, in ImportError: No module named tkMessageBox python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from tkMessageBox import askokcancel >>> it's ok in python2.7 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ozgulfirat at gmail.com Mon Aug 22 08:09:57 2011 From: ozgulfirat at gmail.com (Firat Ozgul) Date: Mon, 22 Aug 2011 09:09:57 +0300 Subject: [Tkinter-discuss] lambada difficult to understand In-Reply-To: References: Message-ID: With lambda your codes will look like this: [code] from Tkinter import * fields = 'Name', 'Job', 'Pay' def fetch(entries): for entry in entries: print 'Input => "%s"' % entry.get() # 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('', lambda x: fetch(ents)) Button(root, text='Fetch', command= lambda: fetch(ents)).pack(side=LEFT) root.mainloop() [/code] However, lambdas sometimes may be hard to read and hard to code. Therefore I recommend you to use functools module instead. With functools your code should look like this: [code] from Tkinter import * from functools import partial fields = 'Name', 'Job', 'Pay' def fetch(entries, event=None): for entry in entries: print 'Input => "%s"' % entry.get() # 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('', partial(fetch, ents)) Button(root, text='Fetch', command= partial(fetch, ents)).pack(side=LEFT) root.mainloop() [/code] 2011/8/22 ???? <1248283536 at qq.com>: > 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: () 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('', (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 at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From ozgulfirat at gmail.com Mon Aug 22 08:14:45 2011 From: ozgulfirat at gmail.com (Firat Ozgul) Date: Mon, 22 Aug 2011 09:14:45 +0300 Subject: [Tkinter-discuss] No module named tkMessageBox in python3.2?? In-Reply-To: References: Message-ID: tkMessageBox has been renamed to messagebox in Python 3.x. Also this module is not available in tkinter. Therefore: [code] >>> from tkinter import messagebox >>> messagebox.showwarning("hello", "world") [/code] 2011/8/22 ???? <1248283536 at qq.com>: > python3.2 > Python 3.2 (r32:88445, Mar 25 2011, 19:28:28) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from tkMessageBox import askokcancel > Traceback (most recent call last): > ? File "", line 1, in > ImportError: No module named tkMessageBox > > python > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from tkMessageBox import askokcancel >>>> > it's ok in python2.7 > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From ozgulfirat at gmail.com Mon Aug 22 08:46:01 2011 From: ozgulfirat at gmail.com (Firat Ozgul) Date: Mon, 22 Aug 2011 09:46:01 +0300 Subject: [Tkinter-discuss] No module named tkMessageBox in python3.2?? In-Reply-To: References: Message-ID: In my previous message I said: "Also this module is **not** available in tkinter". It should be: "Also this "module is **now** available in tkinter". 2011/8/22 ???? <1248283536 at qq.com>: > python3.2 > Python 3.2 (r32:88445, Mar 25 2011, 19:28:28) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from tkMessageBox import askokcancel > Traceback (most recent call last): > ? File "", line 1, in > ImportError: No module named tkMessageBox > > python > Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> from tkMessageBox import askokcancel >>>> > it's ok in python2.7 > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From 1248283536 at qq.com Mon Aug 22 13:14:59 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Mon, 22 Aug 2011 19:14:59 +0800 Subject: [Tkinter-discuss] =?gbk?b?u9i4tKO6ICBsYW1iYWRhIGRpZmZpY3VsdCB0?= =?gbk?q?o_understand?= Message-ID: dear Firat Ozgul: think for your help. you misunderstand my meaning,i want to get the output: print 'Input => "%s"' % entry.get() print event.widget please don't revise the function fetch, from Tkinter import * fields = 'Name', 'Job', 'Pay' def fetch(event,entries): for entry in entries: print 'Input => "%s"' % entry.get() # get text print event.widget 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('', lambda x: fetch(ents)) #how to revise it? Button(root, text='Fetch', command= lambda: fetch(ents)).pack(side=LEFT) # #how to revise it? root.mainloop() how to fix: root.bind('', lambda x: fetch(ents)) Button(root, text='Fetch', command= lambda: fetch(ents)).pack(side=LEFT) to make the code to run ,what i want to get are: print 'Input => "%s"' % entry.get() # get text print event.widget any help appreciated. ------------------ ???? ------------------ ???: "Firat Ozgul"; ????: 2011?8?22?(???) ??2:09 ???: "Tkinter-discuss"; ??: Re: [Tkinter-discuss] lambada difficult to understand With lambda your codes will look like this: [code] from Tkinter import * fields = 'Name', 'Job', 'Pay' def fetch(entries): for entry in entries: print 'Input => "%s"' % entry.get() # 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('', lambda x: fetch(ents)) Button(root, text='Fetch', command= lambda: fetch(ents)).pack(side=LEFT) root.mainloop() [/code] However, lambdas sometimes may be hard to read and hard to code. Therefore I recommend you to use functools module instead. With functools your code should look like this: [code] from Tkinter import * from functools import partial fields = 'Name', 'Job', 'Pay' def fetch(entries, event=None): for entry in entries: print 'Input => "%s"' % entry.get() # 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('', partial(fetch, ents)) Button(root, text='Fetch', command= partial(fetch, ents)).pack(side=LEFT) root.mainloop() [/code] 2011/8/22 ???? <1248283536 at qq.com>: > 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: () 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('', (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 at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: From 1248283536 at qq.com Tue Aug 23 04:19:26 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Tue, 23 Aug 2011 10:19:26 +0800 Subject: [Tkinter-discuss] revise :command=lambda Message-ID: [code] from Tkinter import * fields = 'Name', 'Job', 'Pay' def fetch(event,entries): for entry in entries: print 'Input => "%s"' % entry.get() # get text print event.widget 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('', lambda event,entries=ents: fetch(event,entries)) Button(root, text='Fetch', command= lambda event:fetch(event,entries)).pack(side=LEFT) # #how to revise it? root.mainloop() [/code] in the code ,the bind method is ok, how to revise "command=lambda event:fetch(event,entries)",to make it work too?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From 1248283536 at qq.com Tue Aug 23 11:38:39 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Tue, 23 Aug 2011 17:38:39 +0800 Subject: [Tkinter-discuss] why no sound? Message-ID: here is the code from Tkinter import * class Alarm(Frame): def __init__(self): Frame.__init__(self) self.bell() if __name__ == '__main__': Alarm().mainloop() there is no sound when it run ,why? -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.odonnell at uam.es Tue Aug 23 12:42:59 2011 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Tue, 23 Aug 2011 12:42:59 +0200 Subject: [Tkinter-discuss] why no sound? In-Reply-To: References: Message-ID: Hi, You should always reduce your example code to the bare minimum needed to demonstrate the problem. (often you see the problem yourself in doing that) Your code reduces to: from Tkinter import Frame Frame().bell() Does that work on your machine? If not, check your speakers are turned on and plugged in. Otherwise, what platform are you on? It works for me under python 2.7.1 on Windows 7, I get the bell sound. Mick 2011/8/23 ???? <1248283536 at qq.com>: > here is the code > > from Tkinter import * > > class Alarm(Frame): > ??? def __init__(self): > ??????? Frame.__init__(self) > ??????? self.bell() > > if __name__ == '__main__': > ??? Alarm().mainloop() > > there is no sound when it run ,why? > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > From kevin.buchs at gmail.com Tue Aug 23 14:26:44 2011 From: kevin.buchs at gmail.com (Kevin Buchs) Date: Tue, 23 Aug 2011 07:26:44 -0500 Subject: [Tkinter-discuss] why no sound? In-Reply-To: References: Message-ID: I'm on Ubuntu Natty, with Python 2.7.1 and it doesn't work for me. On Tue, Aug 23, 2011 at 5:42 AM, Michael O'Donnell wrote: > from Tkinter import Frame > Frame().bell() -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.odonnell at uam.es Tue Aug 23 14:49:24 2011 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Tue, 23 Aug 2011 14:49:24 +0200 Subject: [Tkinter-discuss] why no sound? In-Reply-To: References: Message-ID: In a linux terminal, try: xset b on Then try the tkinter coder again. May or may not work, don't have linux here to test it. mick On Tue, Aug 23, 2011 at 2:26 PM, Kevin Buchs wrote: > I'm on Ubuntu Natty, with Python 2.7.1 and it doesn't work for me. > > On Tue, Aug 23, 2011 at 5:42 AM, Michael O'Donnell > wrote: >> >> from Tkinter import Frame >> Frame().bell() From 1248283536 at qq.com Wed Aug 24 04:49:06 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Wed, 24 Aug 2011 10:49:06 +0800 Subject: [Tkinter-discuss] the difference between mainloop and app.mainloop and root.mainloop? Message-ID: #code1 from Tkinter import * class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button ( self, text='Quit', command=self.quit ) self.quitButton.grid() app = Application() app.master.title("Sample application") app.mainloop() #code2 from Tkinter import * class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button ( self, text='Quit', command=self.quit ) self.quitButton.grid() app = Application() app.master.title("Sample application") root=Tk() root.mainloop() #code3 from Tkinter import * class Application(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitButton = Button ( self, text='Quit', command=self.quit ) self.quitButton.grid() app = Application() app.master.title("Sample application") mainloop() code1,code2.code3 all can run , what's the difference between mainloop and app.mainloop and root.mainloop? do they have different meaning?which one is right in code1,code2,code3?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Wed Aug 24 10:39:53 2011 From: klappnase at web.de (Michael Lange) Date: Wed, 24 Aug 2011 10:39:53 +0200 Subject: [Tkinter-discuss] the difference between mainloop and app.mainloop and root.mainloop? In-Reply-To: References: Message-ID: <20110824103953.a3dc7a98.klappnase@web.de> Hi, Thus spoketh "????" <1248283536 at qq.com> unto us on Wed, 24 Aug 2011 10:49:06 +0800: (...) > code1,code2.code3 all can run , > > what's the difference between mainloop and app.mainloop and > root.mainloop? do they have different meaning?which one is right in > code1,code2,code3?? If you want to know things like this, the code from Tkinter.py might be a good source ;) So let's have a look at the methods' definitions; if you search Tkinter.py for "def mainloop" you will find two matches: 1. Tkinter.mainloop(): def mainloop(n=0): """Run the main loop of Tcl.""" _default_root.tk.mainloop(n) (remember, _default_root is in fact the application's Tk() instance) 2. Tkinter.Misc.mainloop(): def mainloop(self, n=0): """Call the mainloop of Tk.""" self.tk.mainloop(n) That is which both the Tk and the Frame class inherit from. So you see that calls to root.mainloop() and mainloop() are equivalent, behind the scene both will call: your_tk_instance.tk.mainloop() Apparently the case is slightly different when you do call app.mainloop(), because then of course your_frame_instance.tk.mainloop() is actually called. So now the question is, if the Tk() and the Frame() widget's tk attribute actually point to the same object. To test this, your friend is the python prompt: >>> from Tkinter import * >>> root = Tk() >>> f = Frame() >>> root.tk == f.tk True >>> root.tk >>> f.tk >>> So you see, all Tkinter widgets share the same object as their tk attribute and so in the end all the calls to mainloop() do exactly the same. I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Time is fluid ... like a river with currents, eddies, backwash. -- Spock, "The City on the Edge of Forever", stardate 3134.0 From klappnase at web.de Wed Aug 24 10:47:58 2011 From: klappnase at web.de (Michael Lange) Date: Wed, 24 Aug 2011 10:47:58 +0200 Subject: [Tkinter-discuss] why no sound? In-Reply-To: References: Message-ID: <20110824104758.1c0632c2.klappnase@web.de> Thus spoketh "Michael O'Donnell" unto us on Tue, 23 Aug 2011 14:49:24 +0200: > In a linux terminal, try: > > xset b on > > Then try the tkinter coder again. > > May or may not work, don't have linux here to test it. > > mick It works here (debian squeeze). I am not sure if the OP is aware of the fact that the "bell" sound is supposed to come out of the PC speaker, not the sound card. So if there is no PC speaker or it is turned off you will not hear a thing. I don't know about windows, on unix systems you could also try a more generic PC speaker test than Frame.bell() with >>> print '\a' >>> from the python prompt or even echo -e "\a" from a standard shell. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Is not that the nature of men and women -- that the pleasure is in the learning of each other? -- Natira, the High Priestess of Yonada, "For the World is Hollow and I Have Touched the Sky", stardate 5476.3. From 1248283536 at qq.com Wed Aug 24 15:57:26 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Wed, 24 Aug 2011 21:57:26 +0800 Subject: [Tkinter-discuss] can't set height in entry? Message-ID: when i run: from Tkinter import * root = Tk() Entry(root,text = 'input your text here',width = 100,height=20).pack() root.mainloop() tkinter.TclError: unknown option "-height" can i have a higher entry? -------------- next part -------------- An HTML attachment was scrubbed... URL: From lionkimbro at gmail.com Wed Aug 24 18:50:08 2011 From: lionkimbro at gmail.com (Lion Kimbro) Date: Wed, 24 Aug 2011 09:50:08 -0700 Subject: [Tkinter-discuss] can't set height in entry? In-Reply-To: References: Message-ID: Entry's don't have height; They only have width. You might be interested in a Text. 2011/8/24 ???? <1248283536 at qq.com> > when i run: > from Tkinter import * > root = Tk() > Entry(root,text = 'input your text here',width = 100,height=20).pack() > root.mainloop() > > tkinter.TclError: unknown option "-height" > > can i have a higher entry? > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Wed Aug 24 20:04:49 2011 From: klappnase at web.de (Michael Lange) Date: Wed, 24 Aug 2011 20:04:49 +0200 Subject: [Tkinter-discuss] the difference between mainloop and app.mainloop and root.mainloop? In-Reply-To: <9184B5BB5F0EE2438C877DF95AD93B510F8E6DD7A8@MAILMBX03.MAIL.LA.GOV> References: <20110824103953.a3dc7a98.klappnase@web.de> <9184B5BB5F0EE2438C877DF95AD93B510F8E6DD7A8@MAILMBX03.MAIL.LA.GOV> Message-ID: <20110824200449.2c6ae4d3.klappnase@web.de> Thus spoketh Steve Oldner unto us on Wed, 24 Aug 2011 06:47:51 -0500: > So all three can be used, but which would be the more 'pythonic' way? How would I dare to decide this ;) ? If we look at the relevant parts of the IDLE code we find the following, and if they do it this way I guess that at least it can't be bad ;) def main(): (...lots of code...) # start editor and/or shell windows: root = Tk(className="Idle") fixwordbreaks(root) root.withdraw() (...some more lots of code...) root.mainloop() root.destroy() if __name__ == "__main__": sys.modules['PyShell'] = sys.modules['__main__'] main() Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Suffocating together ... would create heroic camaraderie. -- Khan Noonian Singh, "Space Seed", stardate 3142.8 From Steven.Oldner at LA.GOV Wed Aug 24 20:26:27 2011 From: Steven.Oldner at LA.GOV (Steve Oldner) Date: Wed, 24 Aug 2011 13:26:27 -0500 Subject: [Tkinter-discuss] the difference between mainloop and app.mainloop and root.mainloop? In-Reply-To: <20110824200449.2c6ae4d3.klappnase@web.de> References: <20110824103953.a3dc7a98.klappnase@web.de> <9184B5BB5F0EE2438C877DF95AD93B510F8E6DD7A8@MAILMBX03.MAIL.LA.GOV> <20110824200449.2c6ae4d3.klappnase@web.de> Message-ID: <9184B5BB5F0EE2438C877DF95AD93B510F8E6DD7AF@MAILMBX03.MAIL.LA.GOV> Thanks. I have seen this in some code snippets, but not have seen the destroy() def main(): root = Tk() #stuff here root.mainloop() if __name__ == '__main__': main() -----Original Message----- From: tkinter-discuss-bounces+steven.oldner=la.gov at python.org [mailto:tkinter-discuss-bounces+steven.oldner=la.gov at python.org] On Behalf Of Michael Lange Sent: Wednesday, August 24, 2011 1:05 PM To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] the difference between mainloop and app.mainloop and root.mainloop? Thus spoketh Steve Oldner unto us on Wed, 24 Aug 2011 06:47:51 -0500: > So all three can be used, but which would be the more 'pythonic' way? How would I dare to decide this ;) ? If we look at the relevant parts of the IDLE code we find the following, and if they do it this way I guess that at least it can't be bad ;) def main(): (...lots of code...) # start editor and/or shell windows: root = Tk(className="Idle") fixwordbreaks(root) root.withdraw() (...some more lots of code...) root.mainloop() root.destroy() if __name__ == "__main__": sys.modules['PyShell'] = sys.modules['__main__'] main() Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Suffocating together ... would create heroic camaraderie. -- Khan Noonian Singh, "Space Seed", stardate 3142.8 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss From klappnase at web.de Wed Aug 24 20:32:52 2011 From: klappnase at web.de (Michael Lange) Date: Wed, 24 Aug 2011 20:32:52 +0200 Subject: [Tkinter-discuss] can't set height in entry? In-Reply-To: References: Message-ID: <20110824203252.183a4188.klappnase@web.de> Hi, Thus spoketh Lion Kimbro unto us on Wed, 24 Aug 2011 09:50:08 -0700: > Entry's don't have height; They only have width. > > You might be interested in a Text. That's of course true if the OP meant to create a multi-line Entry widget. > > 2011/8/24 ???? <1248283536 at qq.com> > > > when i run: > > from Tkinter import * > > root = Tk() > > Entry(root,text = 'input your text here',width = 100,height=20).pack() > > root.mainloop() > > > > tkinter.TclError: unknown option "-height" > > > > can i have a higher entry? However if you just want to change the Entry's visual appearance, you can use a trick and use the geometry manager to vertically stretch the Entry widget (this works at least here on linux, it might depend on the WM's behavior though): from Tkinter import * root = Tk() e=Entry(root,text = 'input your text here',width = 100) e.pack(ipady=10) root.mainloop() BTW, you won't have much luck with the "text" option either, although it does not produce an error message. If you want some default string you will to have to insert it explicitely with the insert() method. A quick overview on the Entry widget's options can be found at: http://www.pythonware.com/library/tkinter/introduction/x4447-options.htm and much more excellent documentation about most of the other Tkinter widgets and the main concepts in Tkinter programming is available at: http://www.pythonware.com/library/tkinter/introduction/ There is also an updated (however not yet complete) version of this book, which also covers some of the newer Tkinter widgets) available at: http://effbot.org/tkinterbook/tkinter-index.htm#class-reference The most complete and up-to-date documentation is of course always the collection of Tk man pages : http://www.tcl.tk/man/tcl8.5/TkCmd/ or, depending on your Tk-version: http://www.tcl.tk/man/tcl8.6/TkCmd/ Of course these require the additional effort to "translate" them into Python, but that is not too hard, and once you got the point, they are quite straightforward to use. I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. What kind of love is that? Not to be loved; never to have shown love. -- Commissioner Nancy Hedford, "Metamorphosis", stardate 3219.8 From 1248283536 at qq.com Thu Aug 25 05:34:04 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Thu, 25 Aug 2011 11:34:04 +0800 Subject: [Tkinter-discuss] event :use command to replace bind Message-ID: here is my code ,it can run ,i want to make it simpler, to change three sentences to one, xb =Button(root, text='Fetch') xb.pack(side=LEFT) xb.bind("", partial(fetch, entries=ents)) i write: Button(root, text='Fetch',command=partial(fetch, entries=ents)).pack(side=LEFT) that is to change code1 into code2 ,when you click the button"fetch",the output is : TypeError: fetch() takes exactly 2 arguments (1 given) how to revise it? code1:(it's 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.widget 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('', partial(fetch, entries=ents)) xb =Button(root, text='Fetch') xb.pack(side=LEFT) xb.bind("", partial(fetch, entries=ents)) root.mainloop() code2: 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.widget 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('', partial(fetch, entries=ents)) Button(root, text='Fetch',command=partial(fetch, entries=ents)).pack(side=LEFT) root.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Thu Aug 25 10:52:04 2011 From: klappnase at web.de (Michael Lange) Date: Thu, 25 Aug 2011 10:52:04 +0200 Subject: [Tkinter-discuss] event :use command to replace bind In-Reply-To: References: Message-ID: <20110825105204.53fc5f56.klappnase@web.de> Hi, Thus spoketh "????" <1248283536 at qq.com> unto us on Thu, 25 Aug 2011 11:34:04 +0800: > here is my code ,it can run ,i want to make it simpler, > to change three sentences to one, > xb =Button(root, text='Fetch') > xb.pack(side=LEFT) > xb.bind("", partial(fetch, entries=ents)) If you want to make your code simpler, I suggest a different approach. Your problem appears to be the way arguments are passed to the fetch() callback. It would be much easier to handle if you did not have to pass the list of Entry widgets to the callback, then your fetch() function could look like: def fetch(event=None): (...code...) With this trick you can use the same callback as a Button command and as a callback with bind() without any additional headaches. The entry list could be stored globally or (better) you create a class based on a Tkinter.Frame that contains all the Entries and make the fetch () callback a class method. A simple example on how to create a custom subclass of Frame can be found here: http://www.java2s.com/Code/Python/GUI-Tk/SubclassFrameanduseit.htm (and if you want to save two lines, omit this example's make_widgets() method and just put the stuff from make_widgets() into __init__() ;) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Madness has no purpose. Or reason. But it may have a goal. -- Spock, "The Alternative Factor", stardate 3088.7 From 1248283536 at qq.com Fri Aug 26 09:18:45 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Fri, 26 Aug 2011 15:18:45 +0800 Subject: [Tkinter-discuss] strange partial function aciton Message-ID: 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('', 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('', 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('', 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('', 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: From spooky.ln at tbs-software.com Fri Aug 26 14:27:42 2011 From: spooky.ln at tbs-software.com (Martin B) Date: Fri, 26 Aug 2011 14:27:42 +0200 Subject: [Tkinter-discuss] Editing text in Canvas Message-ID: <20110826142742.645c88dc@tbs-software.com> Hi all, I'm write some custom widgets for my app. Now i write custom Scale widget like in Gimp2.7. Here is the code: http://www.tbs-software.com/spookyln/py/Tk_Scale.py but i need some kick how to make it editable.When i click to Canvas focus set to editable entry.First value ok and next is error that focus not set in item :( BTW: is possible make gradient fill in Canvas.create_rectangle() ? thanks for info -------------- next part -------------- A non-text attachment was scrubbed... Name: Tk_Scale.py Type: text/x-python Size: 2956 bytes Desc: not available URL: From spooky.ln at tbs-software.com Fri Aug 26 15:27:05 2011 From: spooky.ln at tbs-software.com (Martin B) Date: Fri, 26 Aug 2011 15:27:05 +0200 Subject: [Tkinter-discuss] Editing text in Canvas In-Reply-To: <20110826142742.645c88dc@tbs-software.com> References: <20110826142742.645c88dc@tbs-software.com> Message-ID: <20110826152705.3a5ebc86@tbs-software.com> V Fri, 26 Aug 2011 14:27:42 +0200 Martin B naps?no: sorry for bothering problem is solved. But another raised. How i remove insertion from text object after i hit Return. If i click on canvas insert cursor dissapear but if i write some numbers then these numbers is written in new pos on text object. Thanks From klappnase at web.de Fri Aug 26 21:50:07 2011 From: klappnase at web.de (Michael Lange) Date: Fri, 26 Aug 2011 21:50:07 +0200 Subject: [Tkinter-discuss] Editing text in Canvas In-Reply-To: <20110826152705.3a5ebc86@tbs-software.com> References: <20110826142742.645c88dc@tbs-software.com> <20110826152705.3a5ebc86@tbs-software.com> Message-ID: <20110826215007.6bc7d2c9.klappnase@web.de> Hi, Thus spoketh Martin B unto us on Fri, 26 Aug 2011 15:27:05 +0200: > V Fri, 26 Aug 2011 14:27:42 +0200 > Martin B naps?no: > > sorry for bothering problem is solved. But another raised. > How i remove insertion from text object after i hit Return. > If i click on canvas insert cursor dissapear but if i write some > numbers then these numbers is written in new pos on text object. > Thanks Hm, here I get: Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__ return self.func(*args) File "test7.py", line 79, in __edit_value self.dchars(item, SEL_FIRST, SEL_LAST) File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 2181, in dchars self.tk.call((self._w, 'dchars') + args) TclError: selection isn't in item I guess you changed your code a litle since the last post ? Anyway, your problem is that the Canvas still has keyboard focus and so the __edit_value() callback will be called no matter which of its items the canvas focusses. To understand this you need to be aware that the Canvas' internal focus is not the same as the "normal" widget focus, as "man canvas" says: """Once the focus has been set to an item, the item will display the insertion cursor and all keyboard events will be directed to that item. The focus item within a canvas and the focus window on the screen (set with the focus command) are totally independent: a given item does not actually have the input focus unless (a) its canvas is the focus window and (b) the item is the focus item within the canvas. In most cases it is advisable to follow the focus widget command with the focus command to set the focus window to the canvas (if it was not there already).""" So you need to either add a callback for Button-1 (and maybe other) events that checks the x and y-coords of the event and moves keyboard focus away from the canvas, which could basically look like: self.bind('<1>', self._set_focus, add=True) def _set_focus(self, event): if not self.objects['entry'] in self.find('overlapping', event.x, event.y, event.x, event.y): self.main.focus() or let your __edit_value () callback handle the situation, although I admit that at a quick glance I have no idea how to do that. The third solution that comes to mind seems the best to me: use self.create_window() to replace your text object with an Entry widget which should handle keyboard focus properly. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Vulcans do not approve of violence. -- Spock, "Journey to Babel", stardate 3842.4 From spooky.ln at tbs-software.com Fri Aug 26 22:26:16 2011 From: spooky.ln at tbs-software.com (Martin B) Date: Fri, 26 Aug 2011 22:26:16 +0200 Subject: [Tkinter-discuss] Editing text in Canvas In-Reply-To: <20110826215007.6bc7d2c9.klappnase@web.de> References: <20110826142742.645c88dc@tbs-software.com> <20110826152705.3a5ebc86@tbs-software.com> <20110826215007.6bc7d2c9.klappnase@web.de> Message-ID: <20110826222616.2434e64c@tbs-software.com> Thanks for info. Yes i slowly updating source. using web for my backup sometimes. Now when i arrive from my bike trip with clean head i tried use 'unbind' in __edit_value method and created new bind in __select value. seems to work. as for entry. i dont know how i may change background under entry if filled rect is under object. And for question which i posted before. Is some way to fill this rect with gradient or only way is to create gradient image and use create_bitmap instead create_rect. this is my first idea how to do this. quickly updated source is on web. same link as before. From spooky.ln at tbs-software.com Sat Aug 27 10:26:57 2011 From: spooky.ln at tbs-software.com (Martin B) Date: Sat, 27 Aug 2011 10:26:57 +0200 Subject: [Tkinter-discuss] Editing text in Canvas In-Reply-To: <20110826222616.2434e64c@tbs-software.com> References: <20110826142742.645c88dc@tbs-software.com> <20110826152705.3a5ebc86@tbs-software.com> <20110826215007.6bc7d2c9.klappnase@web.de> <20110826222616.2434e64c@tbs-software.com> Message-ID: <20110827102657.0394890a@tbs-software.com> > And for question which i posted before. Is some way to fill this rect > with gradient or only way is to create gradient image and use > create_bitmap instead create_rect. this is my first idea how to do > this. Hello, problem is solved. Now i implemented vertical and horizontal gradients using Canvas.create_line() From klappnase at web.de Sat Aug 27 10:57:15 2011 From: klappnase at web.de (Michael Lange) Date: Sat, 27 Aug 2011 10:57:15 +0200 Subject: [Tkinter-discuss] Editing text in Canvas In-Reply-To: <20110826222616.2434e64c@tbs-software.com> References: <20110826142742.645c88dc@tbs-software.com> <20110826152705.3a5ebc86@tbs-software.com> <20110826215007.6bc7d2c9.klappnase@web.de> <20110826222616.2434e64c@tbs-software.com> Message-ID: <20110827105715.74888916.klappnase@web.de> Hi, Thus spoketh Martin B unto us on Fri, 26 Aug 2011 22:26:16 +0200: > Thanks for info. > Yes i slowly updating source. using web for my backup sometimes. > > Now when i arrive from my bike trip with clean head i tried use > 'unbind' in __edit_value method and created new bind in __select value. > seems to work. > > as for entry. i dont know how i may change background under entry if > filled rect is under object. You are right, this is not possible. Maybe a way to go is to temporarily create an Entry, as in this example: from Tkinter import * root = Tk() c = Canvas(root) c.pack() textvar = StringVar() t = c.create_text(100, 100, text='foo', anchor='nw') def edit_begin(event): x, y = c.coords(t) textvar.set(c.itemcget(t, 'text')) e = Entry(c, width=5, textvariable=textvar, bd=0, highlightthickness=0, bg=c['bg']) e.selection_range(0, 'end') w = c.create_window(x, y, window=e, tags=('editwindow',), anchor='nw') e.focus_set() e.bind('', edit_end) e.bind('', edit_cancel) def edit_cancel(event): c.delete('editwindow') event.widget.destroy() c.focus_set() def edit_end(event): c.itemconfigure(t, text=textvar.get()) edit_cancel(event) c.bind('', edit_begin) c.focus_set() root.mainloop() Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Earth -- mother of the most beautiful women in the universe. -- Apollo, "Who Mourns for Adonais?" stardate 3468.1 From spooky.ln at tbs-software.com Sat Aug 27 11:44:23 2011 From: spooky.ln at tbs-software.com (Martin B) Date: Sat, 27 Aug 2011 11:44:23 +0200 Subject: [Tkinter-discuss] Editing text in Canvas In-Reply-To: <20110827105715.74888916.klappnase@web.de> References: <20110826142742.645c88dc@tbs-software.com> <20110826152705.3a5ebc86@tbs-software.com> <20110826215007.6bc7d2c9.klappnase@web.de> <20110826222616.2434e64c@tbs-software.com> <20110827105715.74888916.klappnase@web.de> Message-ID: <20110827114423.5e3de0e4@tbs-software.com> Yes this is good idea ! Saved into my examples for later use. Now i quickly updated example on web with gradient fills. No errors check yet. I need rewrite some things etc. etc. BTW : i found on inet TkZinc which use OpenGL for writing into canvas. Someone using this in apps ? thanks From klappnase at web.de Sat Aug 27 12:15:08 2011 From: klappnase at web.de (Michael Lange) Date: Sat, 27 Aug 2011 12:15:08 +0200 Subject: [Tkinter-discuss] Editing text in Canvas In-Reply-To: <20110827102657.0394890a@tbs-software.com> References: <20110826142742.645c88dc@tbs-software.com> <20110826152705.3a5ebc86@tbs-software.com> <20110826215007.6bc7d2c9.klappnase@web.de> <20110826222616.2434e64c@tbs-software.com> <20110827102657.0394890a@tbs-software.com> Message-ID: <20110827121508.06d5cb75.klappnase@web.de> Thus spoketh Martin B unto us on Sat, 27 Aug 2011 10:26:57 +0200: > > > And for question which i posted before. Is some way to fill this rect > > with gradient or only way is to create gradient image and use > > create_bitmap instead create_rect. this is my first idea how to do > > this. > > Hello, problem is solved. > Now i implemented vertical and horizontal gradients using > Canvas.create_line() Can you post a brief example how you implemented the gradients? Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Genius doesn't work on an assembly line basis. You can't simply say, "Today I will be brilliant." -- Kirk, "The Ultimate Computer", stardate 4731.3 From 1248283536 at qq.com Sun Aug 28 04:10:30 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sun, 28 Aug 2011 10:10:30 +0800 Subject: [Tkinter-discuss] one pixel=how many mm? Message-ID: in tkinter ,you can express width in cm ,mm,inch,,pixel i want to know: one pixel=how many mm? -------------- next part -------------- An HTML attachment was scrubbed... URL: From spooky.ln at tbs-software.com Sun Aug 28 08:37:15 2011 From: spooky.ln at tbs-software.com (Martin B) Date: Sun, 28 Aug 2011 08:37:15 +0200 Subject: [Tkinter-discuss] one pixel=how many mm? In-Reply-To: References: Message-ID: <20110828083715.6f359912@tbs-software.com> V Sun, 28 Aug 2011 10:10:30 +0800 "????" <1248283536 at qq.com> naps?no: > in tkinter ,you can express width in cm ,mm,inch,,pixel > i want to know: > one pixel=how many mm? pixels per mm = root.winfo_fpixels('1m') pixels per point = root.winfo_fpixels('1p') pixels per inch = root.winfo_fpixels('1i') pixels per cm = root.winfo_fpixels('1c') From 1248283536 at qq.com Sun Aug 28 11:47:18 2011 From: 1248283536 at qq.com (=?gbk?B?ytjW6rT9zcM=?=) Date: Sun, 28 Aug 2011 17:47:18 +0800 Subject: [Tkinter-discuss] =?gbk?b?u9i4tKO6ICBvbmUgcGl4ZWw9aG93IG1hbnkg?= =?gbk?b?bW0/?= Message-ID: in my computer: xrandr Screen 0: minimum 320 x 200, current 1280 x 800, maximum 8192 x 8192 LVDS1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 331mm x 207mm >>> import Tkinter >>> root=Tkinter.Tk() >>> k=root.winfo_fpixels('1m') >>> print k 3.78698224852 >>> print 1280/k 338.0 why it's 338 ,not 331mm?? ------------------ ???? ------------------ ???: "Martin B"; ????: 2011?8?28?(???) ??2:37 ???: "tkinter-discuss"; ??: Re: [Tkinter-discuss] one pixel=how many mm? V Sun, 28 Aug 2011 10:10:30 +0800 "????" <1248283536 at qq.com> naps?no: > in tkinter ,you can express width in cm ,mm,inch,,pixel > i want to know: > one pixel=how many mm? pixels per mm = root.winfo_fpixels('1m') pixels per point = root.winfo_fpixels('1p') pixels per inch = root.winfo_fpixels('1i') pixels per cm = root.winfo_fpixels('1c') _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: From kalman_g at msn.com Sun Aug 28 19:55:42 2011 From: kalman_g at msn.com (GKalman) Date: Sun, 28 Aug 2011 10:55:42 -0700 (PDT) Subject: [Tkinter-discuss] strange grid-layout manager behaviour Message-ID: <32352525.post@talk.nabble.com> I'm just "switching" from the pack-layout manager to the grid-layout manager. I'm trying to understand why Button b3 is NOT centered like the other two buttons (b1 & b2). See my "mini-script" below. What am I doing wrong? ******************************************* from Tkinter import * #================================================= class Example: def __init__(self, parent): self.parent = parent self.parent.geometry("+400+100") frm1=Frame(self.parent,bg="cyan") frm1.columnconfigure(0,minsize=200) frm1.grid(row=0,column=0) frm3=Frame(self.parent,bg="orange") frm3.columnconfigure(1,minsize=200) frm3.grid(row=0,column=1) frm2=Frame(self.parent,bg="yellow") frm2.columnconfigure(0,minsize=400) frm2.grid(row=1,column=0,columnspan=2) b1=Button(frm1,text="1",bg="green") b1.grid(in_=frm1,row=0,column=0) b3=Button(frm3,text="3",bg="green") b3.grid(in_=frm3,row=0,column=0) b2=Button(frm2,text="2",bg="green") b2.grid(in_=frm2,row=0,column=0) self.parent.grid() #===================================================== def main(): root = Tk() app = Example(root) root.mainloop() #=================================================== if __name__ == '__main__': main() -- View this message in context: http://old.nabble.com/strange-grid-layout-manager-behaviour-tp32352525p32352525.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From kalman_g at msn.com Sun Aug 28 20:00:29 2011 From: kalman_g at msn.com (GKalman) Date: Sun, 28 Aug 2011 11:00:29 -0700 (PDT) Subject: [Tkinter-discuss] strange grid-layout manager behaviour In-Reply-To: <32352525.post@talk.nabble.com> References: <32352525.post@talk.nabble.com> Message-ID: <32352553.post@talk.nabble.com> SORRY, SORRY!!!! I should have been more carefully looking for my TYPOS! Issue [RESOLVED] BTW: Is there a way to remove a post, which was so HASTELY posted? Once again: sorry GKalman wrote: > > I'm just "switching" from the pack-layout manager to the grid-layout > manager. > > I'm trying to understand why Button b3 is NOT centered like the other two > buttons (b1 & b2). See my "mini-script" below. > > What am I doing wrong? > > ******************************************* > > > from Tkinter import * > #================================================= > class Example: > > def __init__(self, parent): > > self.parent = parent > self.parent.geometry("+400+100") > > frm1=Frame(self.parent,bg="cyan") > frm1.columnconfigure(0,minsize=200) > frm1.grid(row=0,column=0) > > frm3=Frame(self.parent,bg="orange") > frm3.columnconfigure(1,minsize=200) > frm3.grid(row=0,column=1) > > frm2=Frame(self.parent,bg="yellow") > frm2.columnconfigure(0,minsize=400) > frm2.grid(row=1,column=0,columnspan=2) > > b1=Button(frm1,text="1",bg="green") > b1.grid(in_=frm1,row=0,column=0) > > b3=Button(frm3,text="3",bg="green") > b3.grid(in_=frm3,row=0,column=0) > > b2=Button(frm2,text="2",bg="green") > b2.grid(in_=frm2,row=0,column=0) > > self.parent.grid() > #===================================================== > def main(): > root = Tk() > app = Example(root) > root.mainloop() > #=================================================== > if __name__ == '__main__': > main() > > -- View this message in context: http://old.nabble.com/strange-grid-layout-manager-behaviour-tp32352525p32352553.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From Cameron at phaseit.net Sun Aug 28 20:39:33 2011 From: Cameron at phaseit.net (Cameron Laird) Date: Sun, 28 Aug 2011 18:39:33 +0000 Subject: [Tkinter-discuss] strange grid-layout manager behaviour In-Reply-To: <32352553.post@talk.nabble.com> References: <32352525.post@talk.nabble.com> <32352553.post@talk.nabble.com> Message-ID: <20110828183933.GC13541@lairds.us> On Sun, Aug 28, 2011 at 11:00:29AM -0700, GKalman wrote: . . . > Is there a way to remove a post, which was so HASTELY posted? . . . It's difficult. I'm probably the one who'd need to take action, and I don't feel motivated enough to undertake it.