From geon at post.cz Mon May 1 18:06:24 2006 From: geon at post.cz (Pavel Kosina) Date: Mon, 01 May 2006 18:06:24 +0200 Subject: [Tkinter-discuss] optionmenu insert Message-ID: <44563200.4030608@post.cz> Hi, I dont know how to dynamically add items to optionmenu. I found this http://aspn.activestate.com/ASPN/docs/ActiveTcl/iwidgets/optionmenu.n.html insert method, but it is not working or wrong done by me. w = OptionMenu(master, variable, *OPTIONS ) w.insert(1,"something") Neither dir(w) nor print w.config() didnt help much. Thank you -- Pavel Kosina From klappnase at web.de Tue May 2 11:12:52 2006 From: klappnase at web.de (Michael Lange) Date: Tue, 2 May 2006 11:12:52 +0200 Subject: [Tkinter-discuss] optionmenu insert In-Reply-To: <44563200.4030608@post.cz> References: <44563200.4030608@post.cz> Message-ID: <20060502111252.7a176475.klappnase@web.de> On Mon, 01 May 2006 18:06:24 +0200 Pavel Kosina wrote: > Hi, > > I dont know how to dynamically add items to optionmenu. > I found this > http://aspn.activestate.com/ASPN/docs/ActiveTcl/iwidgets/optionmenu.n.html > insert method, but it is not working or wrong done by me. > > w = OptionMenu(master, variable, *OPTIONS ) > w.insert(1,"something") > > Neither dir(w) nor print w.config() didnt help much. > Hi Pavel, you can access the OptionMenu's Menu by its 'menu' key: >>> from Tkinter import * >>> root = Tk() >>> s = StringVar() >>> s.set('eggs') >>> o = OptionMenu(root, s, 'eggs', 'spam', 'foo', 'bar') >>> o.pack() >>> o['menu'].insert('end', 'command', label='blah') I hope this helps Michael From geon at post.cz Tue May 2 14:32:17 2006 From: geon at post.cz (Pavel Kosina) Date: Tue, 02 May 2006 14:32:17 +0200 Subject: [Tkinter-discuss] optionmenu insert In-Reply-To: <20060502111252.7a176475.klappnase@web.de> References: <44563200.4030608@post.cz> <20060502111252.7a176475.klappnase@web.de> Message-ID: <44575151.2070809@post.cz> Michael Lange napsal(a): > Hi Pavel, > > you can access the OptionMenu's Menu by its 'menu' key: > > >>>> from Tkinter import * >>>> root = Tk() >>>> s = StringVar() >>>> s.set('eggs') >>>> o = OptionMenu(root, s, 'eggs', 'spam', 'foo', 'bar') >>>> o.pack() >>>> o['menu'].insert('end', 'command', label='blah') >>>> Just found there is another trouble with this. Maybe I could help myself, but dont know how to get from tk documentation what you have written - how to know why "command" should be there, why ["menu"], etc. Anyway, I have: w = OptionMenu(root, var,u"one", u"two", u"...",command=ok) w.pack() w["menu"].insert(2, "command", label=u"three") When I choose "three" then, the function 'ok' is not called. It must be another argument in last line, I think. Thank you -- Pavel Kosina From klappnase at web.de Wed May 3 11:29:12 2006 From: klappnase at web.de (Michael Lange) Date: Wed, 3 May 2006 11:29:12 +0200 Subject: [Tkinter-discuss] optionmenu insert In-Reply-To: <44575151.2070809@post.cz> References: <44563200.4030608@post.cz> <20060502111252.7a176475.klappnase@web.de> <44575151.2070809@post.cz> Message-ID: <20060503112912.62f323ca.klappnase@web.de> On Tue, 02 May 2006 14:32:17 +0200 Pavel Kosina wrote: > Just found there is another trouble with this. Maybe I could help > myself, but dont know how to get from tk documentation what you have > written - how to know why "command" should be there, why ["menu"], etc. > Hi Pavel, the "menu" key is created in Tkinter's OptionMenu class to give us access to the Menu subwidget; optionmenu["menu"] is equivalent with optionmenu.__menu . "command" is there to tell tk what to insert into the menu; try: optionmenu["menu"].insert('end', 'blah') and you get a TclError: _tkinter.TclError: bad menu entry type "blah": must be cascade, checkbutton, command, radiobutton, or separator > Anyway, I have: > > w = OptionMenu(root, var,u"one", u"two", u"...",command=ok) > w.pack() > w["menu"].insert(2, "command", label=u"three") > > When I choose "three" then, the function 'ok' is not called. It must be > another argument in last line, I think. > Oops, you are right. A look at Tkinter.OptionMenu shows that it is not that trivial. Tkinter wraps the command in its internal _setit class, so it should actually be: from Tkinter import _setit w['menu'].insert('end', 'command', label='blah', command=_setit(var, 'blah', ok)) The arguments for the _setit constructor are: _setit(variable, value, callback) . Not very nice, indeed. Maybe it would be a nice improvement to Tkinter to add at least an insert() and a delete() method to Tkinter.OptionMenu . If you do not want to use the "hidden" _setit() you might define another callback for the inserted items: def ok_new(value): var.set(value) ok(value) w['menu'].insert('end', 'command', label='blah', command=lambda : ok_new('blah')) Maybe it is even nicer not to use an OptionMenu command at all and use a trace callback for the variable instead: >>> v = StringVar() >>> v.set('a') >>> def ok(*args): ... print v.get() ... >>> v.trace('w', ok) '-1216076380ok' >>> om = OptionMenu(r, v, 'a', 'b', 'c') >>> om.pack() >>> om['menu'].insert('end', 'command', label='foo', command=lambda : v.set('foo')) At least you do not need a second callback this way. I hope this helps Michael From geon at post.cz Wed May 3 13:37:31 2006 From: geon at post.cz (Pavel Kosina) Date: Wed, 03 May 2006 13:37:31 +0200 Subject: [Tkinter-discuss] optionmenu insert In-Reply-To: <20060503112912.62f323ca.klappnase@web.de> References: <44563200.4030608@post.cz> <20060502111252.7a176475.klappnase@web.de> <44575151.2070809@post.cz> <20060503112912.62f323ca.klappnase@web.de> Message-ID: <445895FB.5000009@post.cz> Michael Lange napsal(a): > Oops, you are right. A look at Tkinter.OptionMenu shows that it is not that trivial. > Tkinter wraps the command in its internal _setit class, so it should actually be: > > from Tkinter import _setit > w['menu'].insert('end', 'command', label='blah', command=_setit(var, 'blah', ok)) > > The arguments for the _setit constructor are: _setit(variable, value, callback) . > > Not very nice, indeed. Maybe it would be a nice improvement to Tkinter to add at least > an insert() and a delete() method to Tkinter.OptionMenu . > yes, really ugly :-) > If you do not want to use the "hidden" _setit() you might define another callback for the inserted items: > > def ok_new(value): > var.set(value) > ok(value) > > w['menu'].insert('end', 'command', label='blah', command=lambda : ok_new('blah')) > this works with me even without new ok_new - with the old one: w['menu'].insert('end', 'command', label='blah', command=lambda : ok('blah')) > Maybe it is even nicer not to use an OptionMenu command at all and use a trace callback for the variable instead: > > >>>> v = StringVar() >>>> v.set('a') >>>> def ok(*args): >>>> > ... print v.get() > ... > >>>> v.trace('w', ok) >>>> > '-1216076380ok' > >>>> om = OptionMenu(r, v, 'a', 'b', 'c') >>>> om.pack() >>>> om['menu'].insert('end', 'command', label='foo', command=lambda : v.set('foo')) >>>> > > I completely forgot about this kind of solution.... > At least you do not need a second callback this way. > > I hope this helps > > Sure this helps. Thank you for all. -- Pavel Kosina -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060503/3558edfe/attachment.html From pjlacroix at hotmail.com Wed May 3 13:53:31 2006 From: pjlacroix at hotmail.com (Peter Lacroix) Date: Wed, 03 May 2006 11:53:31 +0000 Subject: [Tkinter-discuss] A Hello and a Question Message-ID: Hello, I'm new to this list. I've come in search of some answers to questions I hope I can articulate enough to be understood. I would like to know how one would create a button that when clicked would clear the entire set of widgets (including the clicked button itself) and then display a whole new set of widgets. The goal is to write a program that has about 6 different steps the user goes through to submit information. So for instance the first frame would welcome the user and display a "Click to Continue" button. When the button is clicked, the widgets would all disappear and be replaced by a new set of widgets. When these widgets are finsihed being used and the "Continue" or "Submit" button is clicked, again a new set of widgets would replace the old...and so on. I am lost as to how I would design a class(?) that would carry out such a task. Ultimately, when the last set of widgets is finished, the program would revert back to the first set of widgets. Is what I am asking clear? Any help would be appreciated. Peter. _________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ From Cameron at phaseit.net Wed May 3 14:17:02 2006 From: Cameron at phaseit.net (Cameron Laird) Date: Wed, 3 May 2006 12:17:02 +0000 Subject: [Tkinter-discuss] A Hello and a Question In-Reply-To: References: Message-ID: <20060503121702.GB13608@lairds.us> On Wed, May 03, 2006 at 11:53:31AM +0000, Peter Lacroix wrote: . . . > Hello, I'm new to this list. I've come in search of some answers to > questions I hope I can articulate enough to be understood. > > I would like to know how one would create a button that when clicked would > clear the entire set of widgets (including the clicked button itself) and > then display a whole new set of widgets. > > The goal is to write a program that has about 6 different steps the user > goes through to submit information. So for instance the first frame would > welcome the user and display a "Click to Continue" button. When the button > is clicked, the widgets would all disappear and be replaced by a new set of > widgets. When these widgets are finsihed being used and the "Continue" or > "Submit" button is clicked, again a new set of widgets would replace the > old...and so on. > > I am lost as to how I would design a class(?) that would carry out such a > task. Ultimately, when the last set of widgets is finished, the program > would revert back to the first set of widgets. > > Is what I am asking clear? Any help would be appreciated. . . . It's certainly feasible. Before answering the technical question, I recommend a moment more of discussion. *My* first reaction to your description is that your users might like a tabbed display, where finishing the interaction with one tab automatically activates the next. How does that sound to you? My general experience is that it's disquieting to users to erase an entire application display, to start over with a new set of widgets; they do better with an indication of an unchanging "foundation" that structures the display and interaction. From Ilknur.Ozturk at cabot.com.tr Wed May 3 14:36:19 2006 From: Ilknur.Ozturk at cabot.com.tr (Ilknur Ozturk) Date: Wed, 3 May 2006 15:36:19 +0300 Subject: [Tkinter-discuss] A Hello and a Question Message-ID: <79CD3DAD56583A4298D4941761CF687A4484C5@cabottrexch.cabot.local> I am not sure that it solves your question but the example program tt095.py at the link http://www.ferg.org/thinking_in_tkinter/all_programs.html performs such a thing. it can suggest you a way to succeed your aim. -----Original Message----- From: tkinter-discuss-bounces at python.org [mailto:tkinter-discuss-bounces at python.org] On Behalf Of Peter Lacroix Sent: Wednesday, May 03, 2006 2:54 PM To: tkinter-discuss at python.org Subject: [Tkinter-discuss] A Hello and a Question Hello, I'm new to this list. I've come in search of some answers to questions I hope I can articulate enough to be understood. I would like to know how one would create a button that when clicked would clear the entire set of widgets (including the clicked button itself) and then display a whole new set of widgets. The goal is to write a program that has about 6 different steps the user goes through to submit information. So for instance the first frame would welcome the user and display a "Click to Continue" button. When the button is clicked, the widgets would all disappear and be replaced by a new set of widgets. When these widgets are finsihed being used and the "Continue" or "Submit" button is clicked, again a new set of widgets would replace the old...and so on. I am lost as to how I would design a class(?) that would carry out such a task. Ultimately, when the last set of widgets is finished, the program would revert back to the first set of widgets. Is what I am asking clear? Any help would be appreciated. Peter. _________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ********************************************************************** ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ From olivier.feys at gmail.com Wed May 3 14:41:44 2006 From: olivier.feys at gmail.com (Olivier Feys) Date: Wed, 03 May 2006 14:41:44 +0200 Subject: [Tkinter-discuss] A Hello and a Question In-Reply-To: References: Message-ID: <4458A508.9030507@gmail.com> Here is a small example : import Tkinter as tk def change_frame(i,j): frames[i].pack_forget() frames[j].pack() frames = [] r = tk.Tk() #frames that you fill with your widgets f1 = tk.Frame(r) tk.Button(f1,command=lambda :change_frame(0,1),text='go to step 1').pack() f2 = tk.Frame(r) tk.Button(f2,command=lambda :change_frame(1,2),text='go to step 2').pack() f3 = tk.Frame(r) tk.Label(f3,text='step2').pack() frames = [f1,f2,f3] f1.pack() r.mainloop() Peter Lacroix wrote: >Hello, I'm new to this list. I've come in search of some answers to >questions I hope I can articulate enough to be understood. > >I would like to know how one would create a button that when clicked would >clear the entire set of widgets (including the clicked button itself) and >then display a whole new set of widgets. > >The goal is to write a program that has about 6 different steps the user >goes through to submit information. So for instance the first frame would >welcome the user and display a "Click to Continue" button. When the button >is clicked, the widgets would all disappear and be replaced by a new set of >widgets. When these widgets are finsihed being used and the "Continue" or >"Submit" button is clicked, again a new set of widgets would replace the >old...and so on. > >I am lost as to how I would design a class(?) that would carry out such a >task. Ultimately, when the last set of widgets is finished, the program >would revert back to the first set of widgets. > >Is what I am asking clear? Any help would be appreciated. > >Peter. > >_________________________________________________________________ >FREE pop-up blocking with the new MSN Toolbar - get it now! >http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ > >_______________________________________________ >Tkinter-discuss mailing list >Tkinter-discuss at python.org >http://mail.python.org/mailman/listinfo/tkinter-discuss > > > From pjlacroix at hotmail.com Wed May 3 17:21:03 2006 From: pjlacroix at hotmail.com (Peter Lacroix) Date: Wed, 03 May 2006 15:21:03 +0000 Subject: [Tkinter-discuss] A Hello and a Question In-Reply-To: <20060503121702.GB13608@lairds.us> Message-ID: Thanks to Olivier for the sample structure. I think I understand it although I'm not very familiar with 'lambda'. Now Cameron has brought up a good point. By the way, this is an end-of-semester project for students. I am teaching Python for the first time to a high school class - so my knowledge is certainly limited. We have created a few simple programs but all have been command line. So ultimately the goal is simply to learn what GUIs are and play around, not to create anything professional. But Cameron's point is interesting. That is, have a set of tabs that display where in the process of the program the user is. This way they know how far they easily have a visual hold on how far they have to go and how far they've been. Of course, these tabs would not be clickable. I would want the buttons to cause the switch. I think I like that idea. Does it fit with the structure that Olivier offered below? import Tkinter as tk def change_frame(i, j): frames[i].pack_forget() frames[j].pack() frames = [] r = tk.Tk() #frames that you fill with your widgets f1 = tk.Frame(r) tk.Button(f1, command=lambda :change_frame(0,1),text='go to step 1').pack() f2 = tk.Frame(r) tk.Button(f2, command=lambda :change_frame(1,2),text='go to step 2').pack() f3 = tk.Frame(r) tk.Label(f3, text = 'step2').pack() frames = [f1,f2,f3] f1.pack() r.mainloop() From: Cameron Laird Reply-To: claird-dated-1146917583.79ef72 at phaseit.net To: Peter Lacroix CC: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] A Hello and a Question Date: Wed, 3 May 2006 12:17:02 +0000 On Wed, May 03, 2006 at 11:53:31AM +0000, Peter Lacroix wrote: . . . > Hello, I'm new to this list. I've come in search of some answers to > questions I hope I can articulate enough to be understood. > > I would like to know how one would create a button that when clicked would > clear the entire set of widgets (including the clicked button itself) and > then display a whole new set of widgets. > > The goal is to write a program that has about 6 different steps the user > goes through to submit information. So for instance the first frame would > welcome the user and display a "Click to Continue" button. When the button > is clicked, the widgets would all disappear and be replaced by a new set of > widgets. When these widgets are finsihed being used and the "Continue" or > "Submit" button is clicked, again a new set of widgets would replace the > old...and so on. > > I am lost as to how I would design a class(?) that would carry out such a > task. Ultimately, when the last set of widgets is finished, the program > would revert back to the first set of widgets. > > Is what I am asking clear? Any help would be appreciated. . . . It's certainly feasible. Before answering the technical question, I recommend a moment more of discussion. *My* first reaction to your description is that your users might like a tabbed display, where finishing the interaction with one tab automatically activates the next. How does that sound to you? My general experience is that it's disquieting to users to erase an entire application display, to start over with a new set of widgets; they do better with an indication of an unchanging "foundation" that structures the display and interaction. _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From klappnase at web.de Thu May 4 11:17:34 2006 From: klappnase at web.de (Michael Lange) Date: Thu, 4 May 2006 11:17:34 +0200 Subject: [Tkinter-discuss] optionmenu insert In-Reply-To: <445895FB.5000009@post.cz> References: <44563200.4030608@post.cz> <20060502111252.7a176475.klappnase@web.de> <44575151.2070809@post.cz> <20060503112912.62f323ca.klappnase@web.de> <445895FB.5000009@post.cz> Message-ID: <20060504111734.3ab065e2.klappnase@web.de> On Wed, 03 May 2006 13:37:31 +0200 Pavel Kosina wrote: > > > > w['menu'].insert('end', 'command', label='blah', command=lambda : ok_new('blah')) > > > this works with me even without new ok_new - with the old one: > > w['menu'].insert('end', 'command', label='blah', command=lambda : ok('blah')) > It does not change the value of the variable, so the ok() callback will have to do this, like def ok(value): var.set(value) (...) Now, I forgot about this solution, maybe the easiest of all. Michael From klappnase at web.de Thu May 4 11:41:58 2006 From: klappnase at web.de (Michael Lange) Date: Thu, 4 May 2006 11:41:58 +0200 Subject: [Tkinter-discuss] A Hello and a Question In-Reply-To: References: <20060503121702.GB13608@lairds.us> Message-ID: <20060504114158.71d238df.klappnase@web.de> On Wed, 03 May 2006 15:21:03 +0000 "Peter Lacroix" wrote: > > Thanks to Olivier for the sample structure. I think I understand it although > I'm not very familiar with 'lambda'. Now Cameron has brought up a good > point. By the way, this is an end-of-semester project for students. I am > teaching Python for the first time to a high school class - so my knowledge > is certainly limited. We have created a few simple programs but all have > been command line. So ultimately the goal is simply to learn what GUIs are > and play around, not to create anything professional. But Cameron's point is > interesting. That is, have a set of tabs that display where in the process > of the program the user is. This way they know how far they easily have a > visual hold on how far they have to go and how far they've been. Of course, > these tabs would not be clickable. I would want the buttons to cause the > switch. I think I like that idea. Does it fit with the structure that > Olivier offered below? > > import Tkinter as tk > def change_frame(i, j): > frames[i].pack_forget() > frames[j].pack() > > frames = [] > > r = tk.Tk() > > #frames that you fill with your widgets > f1 = tk.Frame(r) > tk.Button(f1, command=lambda :change_frame(0,1),text='go to step 1').pack() > > f2 = tk.Frame(r) > tk.Button(f2, command=lambda :change_frame(1,2),text='go to step 2').pack() > > f3 = tk.Frame(r) > tk.Label(f3, text = 'step2').pack() > > frames = [f1,f2,f3] > > f1.pack() > r.mainloop() > > Maybe you could use a Pmw.NoteBook and disable the tab buttons, like this (untested): from Tkinter import * import Pmw root = Tk() Pmw.initialise(root) nb = Pmw.NoteBook(root) nb.pack(side='top', fill='both', expand=1) def next_page(): pages = nb.pagenames() current = nb.getcurselection() # maybe more testing and changing the button's text here if current == pages[-1]: nb.selectpage(pages[0]) else: nb.nextpage() b = Button(root, text='Next page', command=next_page) b.pack(side='bottom') firstpage = nb.add('firstpage', tab_text='First page', tab_state='disabled', tab_disabledforeground='black') (...)# add widgets and more pages root.mainloop() I hope this helps Michael From electron at borgmeyer.com Thu May 4 14:33:22 2006 From: electron at borgmeyer.com (electron at borgmeyer.com) Date: Thu, 04 May 2006 08:33:22 -0400 Subject: [Tkinter-discuss] How to Reference many Canvas Ovals Message-ID: EHLO! Anyone have code showing how to reference many individual Canvas objects? I've built a large grid of ovals. I plan to have each oval change fill color numerous times based on various changing array values. I haven't yet successfully referenced these oval objects. Examples I've seen are all b1=canvas.create_oval() or similar. I thought tags might be an option, if I could serialize a tag specific to each oval... I'm used to thinking like this: for i in range(1,number+1) n[i] = canvas.create_oval() and if variable[i] == "blue" then canvas.n[i].config(fill='blue') or something. Unfortunately that doesn't work --> SyntaxError: invalid syntax hehe HELP ME OBI-WAN!! YOU'RE MY ONLY HOPE!! From geon at post.cz Thu May 4 17:40:48 2006 From: geon at post.cz (Pavel Kosina) Date: Thu, 04 May 2006 17:40:48 +0200 Subject: [Tkinter-discuss] How to Reference many Canvas Ovals In-Reply-To: References: Message-ID: <445A2080.1010103@post.cz> Hi, electron at borgmeyer.com napsal(a): > EHLO! Anyone have code showing how to reference many individual Canvas > objects? put them into list > for i in range(1,number+1) > n[i] = canvas.create_oval() > instead of this, there should be something like all=[] for i in range(1000): x,y=random.randint(0,X), random.randint(0,Y) o=canvas.create_oval((x,y,x+10,y+10), fill='red') all.append(o) > and > if variable[i] == "blue" then canvas.n[i].config(fill='blue') > no, again, if you want to change color of 578th :-) oval, do it this way: canvas.itemconfig(all[578-1], fill='pink') -- Pavel Kosina From Ilknur.Ozturk at cabot.com.tr Fri May 5 10:04:20 2006 From: Ilknur.Ozturk at cabot.com.tr (Ilknur Ozturk) Date: Fri, 5 May 2006 11:04:20 +0300 Subject: [Tkinter-discuss] writing a function to create button Message-ID: <79CD3DAD56583A4298D4941761CF687A4486D3@cabottrexch.cabot.local> Hi all, I prepared a GUI which contains lots of buttons. Instead of defining each of them one by one, I want to write a function that gets the parameters and create a button.(Each one calls same function for buttonclick event) Is it possible? If it is, can you give me a simple example? Thanks, ilknur ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ********************************************************************** ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060505/72c356dc/attachment.htm From klappnase at web.de Fri May 5 11:42:08 2006 From: klappnase at web.de (Michael Lange) Date: Fri, 5 May 2006 11:42:08 +0200 Subject: [Tkinter-discuss] writing a function to create button In-Reply-To: <79CD3DAD56583A4298D4941761CF687A4486D3@cabottrexch.cabot.local> References: <79CD3DAD56583A4298D4941761CF687A4486D3@cabottrexch.cabot.local> Message-ID: <20060505114208.34a525e5.klappnase@web.de> On Fri, 5 May 2006 11:04:20 +0300 "Ilknur Ozturk" wrote: > Hi all, > > > > I prepared a GUI which contains lots of buttons. Instead of defining > each of them one by one, I want to write a function that gets the > parameters and create a button.(Each one calls same function for > buttonclick event) Is it possible? If it is, can you give me a simple > example? > Hi Ilknur, maybe you mean something like buttons = [] r = 0 c = 0 for i in range(100): b = Button(master, text=i, **kw) b.grid(row=r, column=c) buttons.append(b) c += 1 if c > 10: c = 0 r += 1 I hope this helps Michael From ken at borgmeyer.com Fri May 5 00:04:16 2006 From: ken at borgmeyer.com (Ken Borgmeyer) Date: Thu, 4 May 2006 17:04:16 -0500 Subject: [Tkinter-discuss] How to Reference many Canvas Ovals Message-ID: <000601c66fc6$b90de0a0$6501a8c0@primate> YAHOO! It makes sense and works GREAT! Thank you Pavel! This will make the greatest robot EVER! hehe -----Original Message----- From: Pavel Kosina Sent: Thursday, May 04, 2006 10:41 AM To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] How to Reference many Canvas Ovals Hi, electron > EHLO! Anyone have code showing how to reference many individual Canvas > objects? put them into list > for i in range(1,number+1) > n[i] = canvas.create_oval() > instead of this, there should be something like all=[] for i in range(1000): x,y=random.randint(0,X), random.randint(0,Y) o=canvas.create_oval((x,y,x+10,y+10), fill='red') all.append(o) > and > if variable[i] == "blue" then canvas.n[i].config(fill='blue') > no, again, if you want to change color of 578th :-) oval, do it this way: canvas.itemconfig(all[578-1], fill='pink') -- Pavel Kosina From Ilknur.Ozturk at cabot.com.tr Fri May 5 15:53:30 2006 From: Ilknur.Ozturk at cabot.com.tr (Ilknur Ozturk) Date: Fri, 5 May 2006 16:53:30 +0300 Subject: [Tkinter-discuss] writing a function to create button Message-ID: <79CD3DAD56583A4298D4941761CF687A448769@cabottrexch.cabot.local> Hi Michael, Actually my aim is a little bit different. I put one of the buttons in my code; button_name = "menu" self.menu = Button(self.mycontainer, command=lambda arg1=button_name: self.writecommand(arg1) ) self.menu.configure(text="menu") self.menu.grid(row=2, column=0) ch = "" self.menu.bind(ch, lambda event, arg1=button_name: self.writecommand(arg1) ) This part repeatedly occurs in my code for different buttons, but those buttons placed in a different frames (not each in one, group by group) For each button, button_name, configuration and geometry are changing. It can be divided 2 or more functions if it can be achieved in any way. Thanks, ilknur -----Original Message----- From: tkinter-discuss-bounces at python.org [mailto:tkinter-discuss-bounces at python.org] On Behalf Of Michael Lange Sent: Friday, May 05, 2006 12:42 PM To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] writing a function to create button On Fri, 5 May 2006 11:04:20 +0300 "Ilknur Ozturk" wrote: > Hi all, > > > > I prepared a GUI which contains lots of buttons. Instead of defining > each of them one by one, I want to write a function that gets the > parameters and create a button.(Each one calls same function for > buttonclick event) Is it possible? If it is, can you give me a simple > example? > Hi Ilknur, maybe you mean something like buttons = [] r = 0 c = 0 for i in range(100): b = Button(master, text=i, **kw) b.grid(row=r, column=c) buttons.append(b) c += 1 if c > 10: c = 0 r += 1 I hope this helps Michael _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ********************************************************************** ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ From geon at post.cz Fri May 5 22:00:15 2006 From: geon at post.cz (Pavel Kosina) Date: Fri, 05 May 2006 22:00:15 +0200 Subject: [Tkinter-discuss] mouse pointer Message-ID: <445BAECF.9030302@post.cz> Is it possible to move mouse pointer to given x,y or by given dx, dy? I dont think so, just trying :-) What if ? -- Pavel Kosina From Cameron at phaseit.net Fri May 5 22:57:49 2006 From: Cameron at phaseit.net (Cameron Laird) Date: Fri, 5 May 2006 20:57:49 +0000 Subject: [Tkinter-discuss] mouse pointer In-Reply-To: <445BAECF.9030302@post.cz> References: <445BAECF.9030302@post.cz> Message-ID: <20060505205749.GA972@lairds.us> On Fri, May 05, 2006 at 10:00:15PM +0200, Pavel Kosina wrote: . . . > Is it possible to move mouse pointer to given x,y or by given dx, dy? I > dont think so, just trying :-) What if ? . . . Yes. I think you'll want to read . From geon at post.cz Tue May 9 21:08:48 2006 From: geon at post.cz (Pavel Kosina) Date: Tue, 09 May 2006 21:08:48 +0200 Subject: [Tkinter-discuss] up+right Message-ID: <4460E8C0.1080803@post.cz> I would like to bind f.e. Up and Right, so that when I press both of them, my thing moves sideward up-and-right. How to do that? Thank you -- Pavel Kosina From jepler at unpythonic.net Tue May 9 23:41:43 2006 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 9 May 2006 16:41:43 -0500 Subject: [Tkinter-discuss] up+right In-Reply-To: <4460E8C0.1080803@post.cz> References: <4460E8C0.1080803@post.cz> Message-ID: <20060509214143.GB22863@unpythonic.net> In this example program, the canvas item is moved in the direction indicated by the arrow key(s) pressed. It works by setting a "dx" value when Left or Right is pressed, and then setting "dx" back to 0 when one of those keys is released. Approximately each 20ms the dx and dy values are added to the location of the box, and it's moved on the canvas using coords(). It's probably a good idea to set dx and dy to 0 when you see a event, because when you lose focus you may not see all the KeyRelease events for keys that were pressed at the time. import Tkinter x = y = 150 dx = dy = 0 def wrap(v, l): v = v % l if v < 0: return v + l return v def update(): global x, y x = wrap(x + dx, 300) y = wrap(y + dy, 300) c.coords(item, (x-5, y-5, x+5, y+5)) c.after(20, update) def set_dx(v): global dx; dx = v def set_dy(v): global dy; dy = v t = Tkinter.Tk() t.bind("", lambda e: set_dy(-3)) t.bind("", lambda e: set_dy(3)) t.bind("", lambda e: set_dx(-3)) t.bind("", lambda e: set_dx(3)) t.bind("", lambda e: set_dy(0)) t.bind("", lambda e: set_dy(0)) t.bind("", lambda e: set_dx(0)) t.bind("", lambda e: set_dx(0)) c = Tkinter.Canvas(t, width=300, height=300) c.pack() item = c.create_rectangle((-1,-1,-1,-1), fill="blue", outline="white") update() c.mainloop() From pjlacroix at hotmail.com Thu May 11 13:07:27 2006 From: pjlacroix at hotmail.com (Peter Lacroix) Date: Thu, 11 May 2006 11:07:27 +0000 Subject: [Tkinter-discuss] Radio Buttons In-Reply-To: Message-ID: Hi all, Let's say you had the following class below (MakeChoice) that was used to cast a vote. When the program is running, eventually the user will confirm choices made through some sort of "SUBMIT" button. When that button is clicked, we want the selected value (on a few sets of radio buttons) to be written to a file. What is the container of the currently selected value and how does one have that value be written to a file when a button is clicked? I hope my question is clear. Thanks! --------------------- class MakeChoice(Frame): def __init__(self, master): Frame.__init__(self, master) self.grid() self.create_widgets() def create_widgets(self): # Creates a string variable to bind the five radio buttons together self.current_selection = StringVar() # Choice 1 self.choice1 = Radiobutton( self ) self.choice1["text"] = "Queen Elizabeth" self.choice1["variable"] = self.current_selection, self.choice1["value"] = "Queen Elizabeth", self.choice1["command"] = self.set_text self.choice1.grid( row = 2, column = 0, sticky = W ) # Choice 2 self.choice2 = Radiobutton( self ) self.choice2["text"] = "Madonna" self.choice2["variable"] = self.current_selection, self.choice2["value"] = "Madonna", self.choice2["command"] = self.set_text self.choice2.grid( row = 3, column = 0, sticky = W ) # Choice 3 self.choice3 = Radiobutton( self ) self.choice3["text"] = "Mother Theresa" self.choice3["variable"] = self.current_selection, self.choice3["value"] = "Mother Theresa", self.choice3["command"] = self.set_text self.choice3.grid( row = 4, column = 0, sticky = W ) # Choice 4 self.choice4 = Radiobutton( self ) self.choice4["text"] = "Marge Simpson" self.choice4["variable"] = self.current_selection, self.choice4["value"] = "Marge Simpson", self.choice4["command"] = self.set_text self.choice4.grid( row = 5, column = 0, sticky = W ) # Choice 5 self.choice5 = Radiobutton( self ) self.choice5["text"] = "Abstain" self.choice5["variable"] = self.current_selection, self.choice5["value"] = "abstain. Your vote will be counted but will not reflect a particular choice.", self.choice5["command"] = self.set_text self.choice5.grid( row = 6, column = 0, sticky = W ) # Creates a text field to show the selected option self.selection_text = Text(self, width = 40, height = 3, wrap = WORD) self.selection_text.grid(row = 7, column = 0, columnspan = 3) def set_text( self ): text = "You selected " text += self.current_selection.get() self.selection_text.delete( 0.0, END ) self.selection_text.insert( 0.0, text ) _________________________________________________________________ Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ From klappnase at web.de Thu May 11 18:33:18 2006 From: klappnase at web.de (Michael Lange) Date: Thu, 11 May 2006 18:33:18 +0200 Subject: [Tkinter-discuss] Radio Buttons In-Reply-To: References: Message-ID: <20060511183318.3139e3ca.klappnase@web.de> On Thu, 11 May 2006 11:07:27 +0000 "Peter Lacroix" wrote: > Hi all, > > Let's say you had the following class below (MakeChoice) that was used to > cast a vote. When the program is running, eventually the user will confirm > choices made through some sort of "SUBMIT" button. When that button is > clicked, we want the selected value (on a few sets of radio buttons) to be > written to a file. What is the container of the currently selected value and > how does one have that value be written to a file when a button is clicked? > Hi Peter, do you mean something like this: def create_widgets(self): (... snip ...) self.submit_button = Button(self, text='Submit', command=self.submit) self.submit_button.grid(row=8, column=0) def submit(self): f = open(your_filename_here, 'w') f.write(self.current_selection_get()) f.close() The value of the StringVar is updated automatically each time the user changes the selection. I hope this helps Michael From pjlacroix at hotmail.com Mon May 15 04:56:55 2006 From: pjlacroix at hotmail.com (Peter Lacroix) Date: Mon, 15 May 2006 02:56:55 +0000 Subject: [Tkinter-discuss] Thanks! In-Reply-To: Message-ID: Thanks Michael! Yes this is what I was wondering about. Message: 2 Date: Thu, 11 May 2006 18:33:18 +0200 From: Michael Lange Subject: Re: [Tkinter-discuss] Radio Buttons To: tkinter-discuss at python.org Message-ID: <20060511183318.3139e3ca.klappnase at web.de> Content-Type: text/plain; charset=US-ASCII Hi Peter, do you mean something like this: def create_widgets(self): (... snip ...) self.submit_button = Button(self, text='Submit', command=self.submit) self.submit_button.grid(row=8, column=0) def submit(self): f = open(your_filename_here, 'w') f.write(self.current_selection_get()) f.close() The value of the StringVar is updated automatically each time the user changes the selection. I hope this helps Michael ------------------------------ _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss End of Tkinter-discuss Digest, Vol 27, Issue 8 ********************************************** _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From Ilknur.Ozturk at cabot.com.tr Mon May 15 14:01:58 2006 From: Ilknur.Ozturk at cabot.com.tr (Ilknur Ozturk) Date: Mon, 15 May 2006 15:01:58 +0300 Subject: [Tkinter-discuss] calling function by keypress Message-ID: <79CD3DAD56583A4298D4941761CF687A448F42@cabottrexch.cabot.local> Hi all, I am trying to call my function by keypress. Some specific keys will be assigned to some buttons. All widgets are created in a class. I wrote the code as below: functionalkeys=("Left", "F1",...) def assignkey(self, event): if event.keysym not in self.functionalkeys: return self.callcommand(event.keysym) def callcommand(self, arg1): if arg1=="Left": self.writecommand('left') if arg1=="F1": self.writecommand('menu') .......... else: return and bind assignkey() to my buttons, self.menu=Button(...) self.menu.bind("", self.assignkey) this is working if I focused on the button, otherwise no action. I also bind keypress event to my main frame, but it is also not working. I am new for learning tk and most probably I am doing some basic thing wrong but I could not find it:-( Is there anyone to tell me how can I call the function without focusing the related button? Thanks.... ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ********************************************************************** ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060515/11e4a21d/attachment.htm From mkiever at web.de Tue May 16 13:08:17 2006 From: mkiever at web.de (mkiever at web.de) Date: Tue, 16 May 2006 11:08:17 -0000 Subject: [Tkinter-discuss] calling function by keypress Message-ID: Hello Ilknur, you need focus to get key events. So normally you set focus for the parent of all buttons (or the toplevel widget) and also bind the command to that widget. So: self.focus_set () self.bind ( '', self.assignkey ) in the __init__ of your class should work. (your class needs to be a subclass of some widget, for example Frame) Hope this helps, Matthias Kievernagel Software-Development mkiever/at/web/dot/de From Ilknur.Ozturk at cabot.com.tr Mon May 29 13:54:28 2006 From: Ilknur.Ozturk at cabot.com.tr (Ilknur Ozturk) Date: Mon, 29 May 2006 14:54:28 +0300 Subject: [Tkinter-discuss] calling toplevel creating function Message-ID: <79CD3DAD56583A4298D4941761CF687A48CCEE@cabottrexch.cabot.local> Hi all, I have a problem with toplevel window. It is created within a function and I am calling that function by button press. I have created 4 buttons that call same toplevel creating function. For the first call, there is no problem. The toplevel window is created and get the arguments. But the other call for that function results with an error message like; "Toplevel instance has no __call__ method" I could not solve what is the problem with it? What should I do to solve the problem? Thanks, ilknur ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com ********************************************************************** ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060529/22e68323/attachment.htm From klappnase at web.de Mon May 29 23:30:08 2006 From: klappnase at web.de (Michael Lange) Date: Mon, 29 May 2006 23:30:08 +0200 Subject: [Tkinter-discuss] calling toplevel creating function In-Reply-To: <79CD3DAD56583A4298D4941761CF687A48CCEE@cabottrexch.cabot.local> References: <79CD3DAD56583A4298D4941761CF687A48CCEE@cabottrexch.cabot.local> Message-ID: <20060529233008.2a306791.klappnase@web.de> On Mon, 29 May 2006 14:54:28 +0300 "Ilknur Ozturk" wrote: > Hi all, > > > > I have a problem with toplevel window. It is created within a function > and I am calling that function by button press. I have created 4 buttons > that call same toplevel creating function. For the first call, there is > no problem. The toplevel window is created and get the arguments. But > the other call for that function results with an error message like; > > > > "Toplevel instance has no __call__ method" > Hi Ilknur, can you show us the code and a complete traceback, otherwise we can only guess. The error message you described can be reproduced by the folllowing code snippet: >>> t=Toplevel() >>> t() Traceback (most recent call last): File "", line 1, in ? AttributeError: Toplevel instance has no __call__ method >>> so maybe the problem is the name you give to your Toplevel instance. Michael From Ilknur.Ozturk at cabot.com.tr Tue May 30 23:00:32 2006 From: Ilknur.Ozturk at cabot.com.tr (Ilknur Ozturk) Date: Wed, 31 May 2006 00:00:32 +0300 Subject: [Tkinter-discuss] calling toplevel creating function References: <79CD3DAD56583A4298D4941761CF687A48CCEE@cabottrexch.cabot.local> <20060529233008.2a306791.klappnase@web.de> Message-ID: <79CD3DAD56583A4298D4941761CF687A4C7204@cabottrexch.cabot.local> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060531/fee5c889/attachment.htm From klappnase at web.de Wed May 31 00:32:26 2006 From: klappnase at web.de (Michael Lange) Date: Wed, 31 May 2006 00:32:26 +0200 Subject: [Tkinter-discuss] calling toplevel creating function In-Reply-To: <79CD3DAD56583A4298D4941761CF687A4C7204@cabottrexch.cabot.local> References: <79CD3DAD56583A4298D4941761CF687A48CCEE@cabottrexch.cabot.local> <20060529233008.2a306791.klappnase@web.de> <79CD3DAD56583A4298D4941761CF687A4C7204@cabottrexch.cabot.local> Message-ID: <20060531003226.4f6e1c58.klappnase@web.de> On Wed, 31 May 2006 00:00:32 +0300 "Ilknur Ozturk" wrote: > RE: [Tkinter-discuss] calling toplevel creating function > > Hi Michael, > > my code is below. actually the problem that I explained in my previous mail can be solved by using newkey() instead of self.newkey() toplevel definition.(but still could not understand what is the reason of the error message) Hi Ilknur, self.newkey is the name of the method that creates the Toplevel window, if you name the window self.newkey, too, you override the method. Now when in your self.Button_Press() method the call to self.newkey() occurs, you actually try to "call" the newly created Toplevel window which leads to the error message you saw. however, still I could not reach my aim. As you will see below, I could not assign self.userkey which is gotten from the user on toplevel window, to the userdefinedkey[] array. the aim is, at first click of a key should result with a toplevel window that gets the key parameter from the user. the other press of the same key should result by calling a different function with the parameter taken. there are more than one such a key on my GUI. I hope, I can explain my aim and problems:) thanks from now... The problem here seems similar, if I understand you correctly. Each call to self.newkey() overrides a bunch of variable names. I think a better approach would be to write a separate class for your dialog window; if I understand the use of your dialog window correctly, it is probably the best (and easiest) to use an askstring() dialog from the tkSimpleDialog module, e.g.: (...) # do not forget to make the list a class attribute first self.userdefinedkeys = ['', ''] # define the buttons like this: self.key1 = Button(self.mycontainer, text="Key1", command=lambda index=0 : self.button_press(index)) (...) def button_press(self, index): if self.userdefinedkeys[index]: # alternative callback here print self.userdefinedkeys[index] else: self.userdefinedkeys[index] = tkSimpleDialog.askstring("Enter new key", "Key name:") I hope this helps Michael > > > > from Tkinter import * > > root = Tk() > > class myentryclass: > def __init__(self, parent): > self.myParent = parent > self.myParent.focus_set() > > self.mycontainer = Frame(parent, borderwidth=0) > self.mycontainer.pack() > > > userdefinedkeys=[] > for i in range (2): > userdefinedkeys.append('') > > button_name=self.userdefinedkeys[0] > button_number=1 > self.key1=Button(self.mycontainer, > command=lambda > arg1=button_name, arg2=button_number: > self.Button_Press(arg1, arg2) > ) > self.key1.configure(text="key1") > self.key1.grid(row=3, column=0) > > button_name=self.userdefinedkeys[1] > button_number=2 > self.key2=Button(self.mycontainer, > command=lambda > arg1=button_name, arg2=button_number: > self.Button_Press(arg1, arg2) > ) > self.key2.configure(text="key2") > self.key2.grid(row=3, column=1) > > > def Button_Press(self, arg1, arg2): > if arg2==1: > if arg1=='': > self.newkey() > self.userdefinedkeys[0]=self.userkey > else: > print self.userdefinedkeys[0] > if arg2==2: > if arg1=='': > self.newkey() > self.userdefinedkeys[1]=self.userkey > else: > print self.userdefinedkeys[1] > > else: > pass > > def newkey(self): > newkey=Toplevel() > newkey.title('Define New Key') > newkey.geometry('250x140+500+300') > > self.keydef = Label(newkey, text="Key Name:") > self.keydef.place(x=10, y=10) > self.keyname = Entry(newkey) > self.keyname.focus_set() > self.keyname.place(x=90, y=10) > confirm = Button(newkey, text="OK", width=15, command=self.getkeyname) > confirm.place(x=67, y=85) > > def getkeyname(self): > self.userkey=self.keyname.get() > ## self.newkey.destroy() > print self.userkey > return self.userkey > > > def sendcommand(self, arg1): > print arg1 > > > mylittlentry = myentryclass(root) > root.mainloop() > > From chris at niekel.net Wed May 31 10:23:40 2006 From: chris at niekel.net (Chris Niekel) Date: Wed, 31 May 2006 10:23:40 +0200 Subject: [Tkinter-discuss] Scroll a table, but not the first two rows? Message-ID: <20060531082340.GQ17400@kira.niekel.net> Hi, I'm trying to build a window that has a table with multiple columns. I'm using Pmw.ScrolledFrame now, creating the table with the .grid(row=N,column=N). This works quite good, but when more rows appear than fit in the window, the header of the column scrolls off. Is it possible to have the headers above the columns not scroll, but scroll the data below it? The columns and their header should be aligned properly. Thanks, Chris Niekel From m_tayseer82 at yahoo.com Wed May 31 11:45:20 2006 From: m_tayseer82 at yahoo.com (Mohammad Tayseer) Date: Wed, 31 May 2006 02:45:20 -0700 (PDT) Subject: [Tkinter-discuss] Scroll a table, but not the first two rows? In-Reply-To: <20060531082340.GQ17400@kira.niekel.net> Message-ID: <20060531094520.19281.qmail@web31102.mail.mud.yahoo.com> Why don't you separate the table from the header? The header should be *outside* the ScrolledFrame, so it's not scrolled Chris Niekel wrote: Hi, I'm trying to build a window that has a table with multiple columns. I'm using Pmw.ScrolledFrame now, creating the table with the .grid(row=N,column=N). This works quite good, but when more rows appear than fit in the window, the header of the column scrolls off. Is it possible to have the headers above the columns not scroll, but scroll the data below it? The columns and their header should be aligned properly. Thanks, Chris Niekel _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060531/569f0634/attachment.html From chris at niekel.net Wed May 31 13:06:57 2006 From: chris at niekel.net (Chris Niekel) Date: Wed, 31 May 2006 13:06:57 +0200 Subject: [Tkinter-discuss] Scroll a table, but not the first two rows? Message-ID: <20060531110657.GS17400@kira.niekel.net> On Wed, May 31, 2006 at 02:45:20AM -0700, Mohammad Tayseer wrote: > Why don't you separate the table from the header? The header should be > *outside* the ScrolledFrame, so it's not scrolled Then the grids are different, and the columns are not aligned anymore. Or is there a way to force that? (Sorry Mohammad for sending you an extra reply) Chris From klappnase at web.de Wed May 31 13:18:58 2006 From: klappnase at web.de (Michael Lange) Date: Wed, 31 May 2006 13:18:58 +0200 Subject: [Tkinter-discuss] Scroll a table, but not the first two rows? In-Reply-To: <20060531110657.GS17400@kira.niekel.net> References: <20060531110657.GS17400@kira.niekel.net> Message-ID: <20060531131858.4df4369e.klappnase@web.de> On Wed, 31 May 2006 13:06:57 +0200 Chris Niekel wrote: > On Wed, May 31, 2006 at 02:45:20AM -0700, Mohammad Tayseer wrote: > > Why don't you separate the table from the header? The header should be > > *outside* the ScrolledFrame, so it's not scrolled > > Then the grids are different, and the columns are not aligned anymore. Or > is there a way to force that? > Hi Chris, maybe you can calculate the needed width for the header and the associated column and then configure both to have the same width. If you bind this method to events for both the header and the column you should be able to make sure that the width will be updated every time the needed width of the column changes. I hope this helps Michael From stewart.midwinter at gmail.com Wed May 31 15:50:56 2006 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed, 31 May 2006 07:50:56 -0600 Subject: [Tkinter-discuss] Scroll a table, but not the first two rows? In-Reply-To: <20060531082340.GQ17400@kira.niekel.net> References: <20060531082340.GQ17400@kira.niekel.net> Message-ID: just curious, why not use the MCListbox widget instead of hand-rolling your own widget using ScrolledFrame? as a bonus, the MCListbox has settable widths for the columns. You could create two of them inside a frame, use the top one for your headers,and the bottom one for data. You should be able to find the widget here: http://pmwcontribd.sourceforge.net/ cheers Stewart On 5/31/06, Chris Niekel wrote: > Hi, > > I'm trying to build a window that has a table with multiple columns. I'm From rowen at cesmail.net Wed May 31 22:27:36 2006 From: rowen at cesmail.net (Russell E. Owen) Date: Wed, 31 May 2006 13:27:36 -0700 Subject: [Tkinter-discuss] Scroll a table, but not the first two rows? References: <20060531110657.GS17400@kira.niekel.net> <20060531131858.4df4369e.klappnase@web.de> Message-ID: In article <20060531131858.4df4369e.klappnase at web.de>, Michael Lange wrote: > On Wed, 31 May 2006 13:06:57 +0200 > Chris Niekel wrote: > > > On Wed, May 31, 2006 at 02:45:20AM -0700, Mohammad Tayseer wrote: > > > Why don't you separate the table from the header? The header should be > > > *outside* the ScrolledFrame, so it's not scrolled > > > > Then the grids are different, and the columns are not aligned anymore. Or > > is there a way to force that? > > > Hi Chris, > > maybe you can calculate the needed width for the header and the associated > column and then > configure both to have the same width. If you bind this method to > events for > both the header and the column you should be able to make sure that the width > will > be updated every time the needed width of the column changes. That's how I manage it. It's rather ugly, but it works. I sure wish Tkinter had a nice table widget. Anyway, here's a code fragment (using bare Tkinter; I don't use pmw). The basic architecture (which is a bit weird and perhaps not ideal) is: - The main widget produces a title frame, the vertical scroll bar and the scrolled table. - The scrolled table is implemented as a widget that not only creates the main table, but also fills in the titles in the title frame. The code fragment is from this latter widget (and the title frame was passed in as an argument to __init___): def _addTitle(self, text, col): """Create and grid a title label and two associated width measuring frames (one in the title frame, one in the main frame). Inputs: - text text for title - col column for title """ strWdg = Tkinter.Label(self._titleFrame, text=text) strWdg.grid(row=0, column=col) titleSpacer = Tkinter.Frame(self._titleFrame) titleSpacer.grid(row=1, column=col, sticky="ew") mainSpacer = Tkinter.Frame(self) mainSpacer.grid(row=2, column=col, sticky="ew") def dotitle(evt): if titleSpacer.winfo_width() > mainSpacer.winfo_width(): mainSpacer["width"] = titleSpacer.winfo_width() titleSpacer.bind("", dotitle) def domain(evt): if mainSpacer.winfo_width() > titleSpacer.winfo_width(): titleSpacer["width"] = mainSpacer.winfo_width() mainSpacer.bind("", domain) To see the whole thing, download TUI source from here and look at TUI/TUIMenu/Permissions/ (PermisWindow.py imlements the high-level window; PermisInputWdg.py implements the scrolled table) From Cameron at phaseit.net Wed May 31 23:03:01 2006 From: Cameron at phaseit.net (Cameron Laird) Date: Wed, 31 May 2006 21:03:01 +0000 Subject: [Tkinter-discuss] Scroll a table, but not the first two rows? In-Reply-To: References: <20060531110657.GS17400@kira.niekel.net> <20060531131858.4df4369e.klappnase@web.de> Message-ID: <20060531210301.GA20980@lairds.us> On Wed, May 31, 2006 at 01:27:36PM -0700, Russell E. Owen wrote: . . . > That's how I manage it. It's rather ugly, but it works. I sure wish > Tkinter had a nice table widget. > > Anyway, here's a code fragment (using bare Tkinter; I don't use pmw). . . . Hmmm; I take it that isn't for you. On the other hand, you might combine and . From stewart.midwinter at gmail.com Wed May 31 23:18:43 2006 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed, 31 May 2006 15:18:43 -0600 Subject: [Tkinter-discuss] Scroll a table, but not the first two rows? In-Reply-To: <20060531210301.GA20980@lairds.us> References: <20060531110657.GS17400@kira.niekel.net> <20060531131858.4df4369e.klappnase@web.de> <20060531210301.GA20980@lairds.us> Message-ID: On 5/31/06, Cameron Laird wrote: > > On the other hand, you might combine > http://wiki.python.org/moin/How_Tkinter_can_exploit_Tcl/Tk_extensions?highlight=%28tkinter%29> > Nice tip! Sure opens up the spectrum for Tkinter, by allowing us to make better use of the wide range of Tcl widgets without having to take on the task of writing a Tkinter wrapper for them. (or did I miss something?). cheers Stewart -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20060531/7e9bcb1c/attachment.html