From Vasilis.Vlachoudis at cern.ch Thu Jul 1 16:30:25 2010 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Thu, 1 Jul 2010 16:30:25 +0200 Subject: [Tkinter-discuss] How to capture exceptions after the end of the program In-Reply-To: <20100625223914.150cfe1c.klappnase@web.de> References: <4C2482EE.9080703@cern.ch> <20100625223914.150cfe1c.klappnase@web.de> Message-ID: <4C2CA681.2060709@cern.ch> Unfortunately I was not able to narrow down to a simple code. All my attempts failed and they worked ok. While in the big project is not behaving correctly. The problem I see depends on the gc. If the gc deletes first the Tk_ root window then when it tries to delete the Font.__del__, tcl fails. Which for me is a bit puzzling since there is a backlink of the root in the Font class. However I saw that from python 2.6 the tkFont.Font.__del__ method has changed with respect to the 2.4 and there is a branch to catch the generic exception. When I added this to the tkFont of the 2.4 it worked and absorbed all Exceptions. Vasilis On 06/25/10 22:39, Michael Lange wrote: > Hi Vasilis, > > On Fri, 25 Jun 2010 12:20:30 +0200 > Vasilis Vlachoudis wrote: > > >> Hi all, >> >> I have a tkinter application that uses several fonts. However only >> with python 2.4 when the application is closed then I get the >> following exceptions (with 2.6 it works Ok) >> >> Exception exceptions.AttributeError: "'NoneType' object has no >> attribute 'TclError'" in> instance at >> 0x2ac0dd4c4908>> ignored >> Exception exceptions.AttributeError: "'NoneType' object has no >> attribute 'TclError'" in> instance at >> 0x2ac0dd4c4680>> ignored >> >> and I have no way of capturing them since they arrive even after the >> last line of the program. >> I believe that for some reason the tkinter is deleted before and >> afterwards it tries to delete the fonts and creates the TclError. >> Is there a way to protect for these exceptions? >> >> I was getting the same problem with the PhotoImage() but now I am >> trying to delete all of them before the end of the program to avoid >> the exceptions. However with fonts I can miss something e.g replace a >> font and exit afterwards. >> >> > Can you provide a minimal code example that exhibits the problem? > > Michael > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- ------------------------------------------------------- Vasilis Vlachoudis Dep. EN-STI-EET Web: home.cern.ch/bnv Tel: +41-22-7679851 Fax: +41-22-7669644 ------------------------------------------------------- From charras at me.com Sat Jul 10 18:52:11 2010 From: charras at me.com (Guido Carballo-Guerrero) Date: Sat, 10 Jul 2010 10:52:11 -0600 Subject: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk Message-ID: <0BBE8283-A1F0-4AD7-97B6-805D029739C7@me.com> Hello, I just update my Python version to 2.7. I was doing some programs using Tkinter and ttk. By the way I have a Mac running 10.6.4. Well, after I install Python, I install ActivePython2.6.5--I try to install 2.7.0 but at the end of the installation it gave me an error message--and ActiveTcl, this 'cause I discover that if I didn't do that, Python will use Tcl and Tk 8.4, which doesn't allow me to use ttk. No my problem is that I can't use Python's IDLE. Well, I can only open one window at a time. If I try to open a new window to make a program, Python freeze. Some curios, if that if I don't have Python open, and double click on a program, Python opens the IDLE and the program in to separate windows without a problem, but when I try to run the program it freeze. I guess that this is a bug somewhere in the ttk implementation, or in Python. Do you guys have any idea how can I solve this? Or have anybody update Python to 2.7, and use ttk on a Mac? If so, please let me know how you manage to do it. Regards! Guido From nulla.epistola at web.de Sun Jul 11 10:07:30 2010 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sun, 11 Jul 2010 10:07:30 +0200 (CEST) Subject: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk In-Reply-To: <0BBE8283-A1F0-4AD7-97B6-805D029739C7@me.com> References: <0BBE8283-A1F0-4AD7-97B6-805D029739C7@me.com> Message-ID: <1462469060.602770.1278835650962.JavaMail.fmail@mwmweb034> -----Urspr?ngliche Nachricht----- Von: Guido Carballo-Guerrero >No my problem is that I can't use Python's IDLE. Well, I can only open one window at a time. If I try to open a new window to make a program, Python freeze. Some curios, if that if I don't have Python open, and double click on a program, Python opens the IDLE and the program in to separate windows without a problem, but when I try to run the program it freeze. > >I guess that this is a bug somewhere in the ttk implementation, or in Python. Do you guys have any idea how can I solve this? Or have anybody update Python to 2.7, and use ttk on a Mac? If so, please let me know how you manage to do it. > As far as I know this is just because IDLE is written in tkinter. So if you try to run another tkinter application from IDLE, the two mainloop() calls interfere with each other. You should be able to run console applications from IDLE, but with tkinter applications you can develop them using IDLE but run them from a console (or whatever is used as a console on a Mac). It's nothing to do with the Python version or with ttk and I doubt it can be called a bug. HTH Sibylle ___________________________________________________________ WEB.DE DSL ab 19,99 Euro/Monat. Bis zu 150,- Euro Startguthaben und 50,- Euro Geldpr?mie inklusive! https://freundschaftswerbung.web.de From Cameron at phaseit.net Sun Jul 11 13:58:44 2010 From: Cameron at phaseit.net (Cameron Laird) Date: Sun, 11 Jul 2010 11:58:44 +0000 Subject: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk In-Reply-To: <1462469060.602770.1278835650962.JavaMail.fmail@mwmweb034> References: <0BBE8283-A1F0-4AD7-97B6-805D029739C7@me.com> <1462469060.602770.1278835650962.JavaMail.fmail@mwmweb034> Message-ID: <20100711115844.GA31927@lairds.us> On Sun, Jul 11, 2010 at 10:07:30AM +0200, Sibylle Koczian wrote: . . . > Von: Guido Carballo-Guerrero > >No my problem is that I can't use Python's IDLE. Well, I can only open one window at a time. If I try to open a new window to make a program, Python freeze. Some curios, if that if I don't have Python open, and double click on a program, Python opens the IDLE and the program in to separate windows without a problem, but when I try to run the program it freeze. > > > >I guess that this is a bug somewhere in the ttk implementation, or in Python. Do you guys have any idea how can I solve this? Or have anybody update Python to 2.7, and use ttk on a Mac? If so, please let me know how you manage to do it. > > > As far as I know this is just because IDLE is written in tkinter. So if you try to run another tkinter application from IDLE, the two mainloop() calls interfere with each other. You should be able to run console applications from IDLE, but with tkinter applications you can develop them using IDLE but run them from a console (or whatever is used as a console on a Mac). It's nothing to do with the Python version or with ttk and I doubt it can be called a bug. . . . If one is clever and motivated, it's possible to code a Tkinter application in a way that permits it to be run (apparently) within IDLE. I don't think I've ever seen it documented well ... All that Sibylle Koczian writes is true, though, and, in particular, a conventional Tkinter application simply is incom- patible with IDLE. From michael.odonnell at uam.es Sun Jul 11 18:01:59 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Sun, 11 Jul 2010 18:01:59 +0200 Subject: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk In-Reply-To: <20100711115844.GA31927@lairds.us> References: <0BBE8283-A1F0-4AD7-97B6-805D029739C7@me.com> <1462469060.602770.1278835650962.JavaMail.fmail@mwmweb034> <20100711115844.GA31927@lairds.us> Message-ID: Hi all, >> As far as I know this is just because IDLE is written in tkinter. So if you try to run another > tkinter application from IDLE, the two mainloop() calls interfere with each other. You should be > able to run console applications from IDLE, but with tkinter applications you can develop them > using IDLE but run them from a console (or whatever is used as a console on a Mac). It's > nothing to do with the Python version or with ttk and I doubt it can be called a bug. I don't understand this, I have been running my tkinter based applications from within IDLE for years, on Mac, PC or Linux. Am I misunderstanding something? My biggest problems with IDLE on the Mac have been when python has been compiled against one version of the tcl/tk libraries but python is finding a different version of tcl/tk. Sometimes I have needed to recompile python from sources. Other times I have installed the asked-for version of tcl from ActiveState. Try running idle from a terminal window. That way you can see the error message when idle crashes. May suggest that the wrong tcl is installed. Mick On Sun, Jul 11, 2010 at 1:58 PM, Cameron Laird wrote: > On Sun, Jul 11, 2010 at 10:07:30AM +0200, Sibylle Koczian wrote: > ? ? ? ? ? ? ? ? ? ? ? ?. > ? ? ? ? ? ? ? ? ? ? ? ?. > ? ? ? ? ? ? ? ? ? ? ? ?. >> Von: Guido Carballo-Guerrero >> >No my problem is that I can't use Python's IDLE. Well, I can only open one window at a time. If I try to open a new window to make a program, Python freeze. Some curios, if that if I don't have Python open, and double click on a program, Python opens the IDLE and the program in to separate windows without a problem, but when I try to run the program it freeze. >> > >> >I guess that this is a bug somewhere in the ttk implementation, or in Python. Do you guys have any idea how can I solve this? Or have anybody update Python to 2.7, and use ttk on a Mac? If so, please let me know how you manage to do it. >> > >> As far as I know this is just because IDLE is written in tkinter. So if you try to run another tkinter application from IDLE, the two mainloop() calls interfere with each other. You should be able to run console applications from IDLE, but with tkinter applications you can develop them using IDLE but run them from a console (or whatever is used as a console on a Mac). It's nothing to do with the Python version or with ttk and I doubt it can be called a bug. > ? ? ? ? ? ? ? ? ? ? ? ?. > ? ? ? ? ? ? ? ? ? ? ? ?. > ? ? ? ? ? ? ? ? ? ? ? ?. > If one is clever and motivated, it's possible to code a Tkinter > application in a way that permits it to be run (apparently) > within IDLE. ?I don't think I've ever seen it documented well > ... ?All that Sibylle Koczian writes is true, though, and, in > particular, a conventional Tkinter application simply is incom- > patible with IDLE. > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From charras at me.com Sun Jul 11 20:18:52 2010 From: charras at me.com (Guido Carballo-Guerrero) Date: Sun, 11 Jul 2010 12:18:52 -0600 Subject: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk In-Reply-To: References: Message-ID: <6DA70420-97A4-4B4E-9B0C-8377B897910D@me.com> Well, I fix the problem. The best to install Python on a Mac is to download the source files and do: $ ./configure --enable-universalsdk --enable-framework $ make $ make frameworkinstall Inside of the folder where you have all the files of the source. Something to remember is that you need to have SDK install in the computer. But after I did this, now I can use Python, Tkinter and ttk without any problems. And I notice that in some of the lines after one type make, Tcl, and Tk frameworks are call. Now if I do: >>> import Tkinter as Tkt >>> Tkt.TclVersion 8.5 As you can see the Tcl version is 8.5, which is what ttk needs to run without problems. Regards! Guido On Jul 11, 2010, at 4:00 AM, tkinter-discuss-request at python.org wrote: > Send Tkinter-discuss mailing list submissions to > tkinter-discuss at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tkinter-discuss > or, via email, send a message with subject or body 'help' to > tkinter-discuss-request at python.org > > You can reach the person managing the list at > tkinter-discuss-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tkinter-discuss digest..." > Today's Topics: > > 1. Tkinter (IDLE) freeze when I try to use ttk > (Guido Carballo-Guerrero) > 2. Re: Tkinter (IDLE) freeze when I try to use ttk (Sibylle Koczian) > > From: Guido Carballo-Guerrero > Date: July 10, 2010 10:52:11 AM GMT-06:00 > To: tkinter-discuss at python.org > Subject: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk > > > Hello, I just update my Python version to 2.7. I was doing some programs using Tkinter and ttk. By the way I have a Mac running 10.6.4. Well, after I install Python, I install ActivePython2.6.5--I try to install 2.7.0 but at the end of the installation it gave me an error message--and ActiveTcl, this 'cause I discover that if I didn't do that, Python will use Tcl and Tk 8.4, which doesn't allow me to use ttk. > > No my problem is that I can't use Python's IDLE. Well, I can only open one window at a time. If I try to open a new window to make a program, Python freeze. Some curios, if that if I don't have Python open, and double click on a program, Python opens the IDLE and the program in to separate windows without a problem, but when I try to run the program it freeze. > > I guess that this is a bug somewhere in the ttk implementation, or in Python. Do you guys have any idea how can I solve this? Or have anybody update Python to 2.7, and use ttk on a Mac? If so, please let me know how you manage to do it. > > Regards! > > Guido > > > > > From: Sibylle Koczian > Date: July 11, 2010 2:07:30 AM GMT-06:00 > To: tkinter-discuss at python.org > Subject: Re: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk > > > -----Urspr?ngliche Nachricht----- > Von: Guido Carballo-Guerrero >> No my problem is that I can't use Python's IDLE. Well, I can only open one window at a time. If I try to open a new window to make a program, Python freeze. Some curios, if that if I don't have Python open, and double click on a program, Python opens the IDLE and the program in to separate windows without a problem, but when I try to run the program it freeze. >> >> I guess that this is a bug somewhere in the ttk implementation, or in Python. Do you guys have any idea how can I solve this? Or have anybody update Python to 2.7, and use ttk on a Mac? If so, please let me know how you manage to do it. >> > As far as I know this is just because IDLE is written in tkinter. So if you try to run another tkinter application from IDLE, the two mainloop() calls interfere with each other. You should be able to run console applications from IDLE, but with tkinter applications you can develop them using IDLE but run them from a console (or whatever is used as a console on a Mac). It's nothing to do with the Python version or with ttk and I doubt it can be called a bug. > > HTH > Sibylle > ___________________________________________________________ > WEB.DE DSL ab 19,99 Euro/Monat. Bis zu 150,- Euro Startguthaben und > 50,- Euro Geldpr?mie inklusive! https://freundschaftswerbung.web.de > > > > _______________________________________________ > 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 greg.ewing at canterbury.ac.nz Mon Jul 12 02:34:34 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 12 Jul 2010 12:34:34 +1200 Subject: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk In-Reply-To: <1462469060.602770.1278835650962.JavaMail.fmail@mwmweb034> References: <0BBE8283-A1F0-4AD7-97B6-805D029739C7@me.com> <1462469060.602770.1278835650962.JavaMail.fmail@mwmweb034> Message-ID: <4C3A631A.50400@canterbury.ac.nz> Sibylle Koczian wrote: > As far as I know this is just because IDLE is written in tkinter. > So if you try to run another tkinter application from IDLE, the two > mainloop() calls interfere with each other. I thought IDLE had an option to run things in a separate process nowadays. -- Greg From sridharr at activestate.com Mon Jul 12 19:08:42 2010 From: sridharr at activestate.com (Sridhar Ratnakumar) Date: Mon, 12 Jul 2010 10:08:42 -0700 Subject: [Tkinter-discuss] Tkinter (IDLE) freeze when I try to use ttk In-Reply-To: <0BBE8283-A1F0-4AD7-97B6-805D029739C7@me.com> References: <0BBE8283-A1F0-4AD7-97B6-805D029739C7@me.com> Message-ID: On 2010-07-10, at 9:52 AM, Guido Carballo-Guerrero wrote: > Hello, I just update my Python version to 2.7. I was doing some programs using Tkinter and ttk. By the way I have a Mac running 10.6.4. Well, after I install Python, I install ActivePython2.6.5--I try to install 2.7.0 but at the end of the installation it gave me an error message--and ActiveTcl, this 'cause I discover that if I didn't do that, Python will use Tcl and Tk 8.4, which doesn't allow me to use ttk. Hi there - Were you using ActivePython 2.7? It was not clear from your message. ActivePython 2.7 is built against Tcl/Tk 8.5; on Mac 10.6 it therefore uses Apple's Tcl/Tk (8.5) in /System/Library/Frameworks. ActiveTcl 8.5 (which does not have 64-bit support yet) need not be installed. cf. http://docs.activestate.com/activepython/2.7/faq.html#how-do-i-use-tkinter-or-idle-in-64-bit-activepython-on-osx-10-5 -srid From kalman_g at msn.com Tue Jul 20 19:00:26 2010 From: kalman_g at msn.com (GKalman) Date: Tue, 20 Jul 2010 10:00:26 -0700 (PDT) Subject: [Tkinter-discuss] Widget to appear square-shaped on screen... Message-ID: <29216127.post@talk.nabble.com> I'm trying to make a square-shaped board, something like this: from Tkinter import * root = Tk() w=[] for k in range(9): i=k/3 j=k%3 w.append(Label(root,text=str(k),bg="red",width=5,height=5)) w[k].grid(row=i,column=j,padx=2,pady=2,ipadx=5,ipady=5) mainloop() It shows up on my screen as rectangular (non-square) shaped. What do I have to do to make it appear in a square-shaped form (i.e. with Label height & width to be equal on the sceen)? -- View this message in context: http://old.nabble.com/Widget-to-appear-square-shaped-on-screen...-tp29216127p29216127.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From waynejwerner at gmail.com Tue Jul 20 19:45:31 2010 From: waynejwerner at gmail.com (Wayne Werner) Date: Tue, 20 Jul 2010 12:45:31 -0500 Subject: [Tkinter-discuss] Widget to appear square-shaped on screen... In-Reply-To: <29216127.post@talk.nabble.com> References: <29216127.post@talk.nabble.com> Message-ID: On Tue, Jul 20, 2010 at 12:00 PM, GKalman wrote: > > I'm trying to make a square-shaped board, something like this: > > from Tkinter import * > > root = Tk() > w=[] > for k in range(9): > i=k/3 > j=k%3 > w.append(Label(root,text=str(k),bg="red",width=5,height=5)) > w[k].grid(row=i,column=j,padx=2,pady=2,ipadx=5,ipady=5) > mainloop() > > It shows up on my screen as rectangular (non-square) shaped. What do I have > to do to make it appear in a square-shaped form (i.e. with Label height & > width to be equal on the sceen)? That's because when you put text on a label the height and width are based on text height and width. Since those two are *not* equal for 99% of fonts, you'll get weird dimensions. You can get around it by following the directions here: http://effbot.org/tkinterbook/button.htm HTH, Wayne -------------- next part -------------- An HTML attachment was scrubbed... URL: From rgomez at autotrol.com.ar Tue Jul 20 19:55:51 2010 From: rgomez at autotrol.com.ar (Roberto Gomez) Date: Tue, 20 Jul 2010 14:55:51 -0300 Subject: [Tkinter-discuss] Widget to appear square-shaped on screen... In-Reply-To: <29216127.post@talk.nabble.com> References: <29216127.post@talk.nabble.com> Message-ID: GKalman wrote: > I'm trying to make a square-shaped board, something like this: > > from Tkinter import * > > root = Tk() > w=[] > for k in range(9): > i=k/3 > j=k%3 > w.append(Label(root,text=str(k),bg="red",width=5,height=5)) > w[k].grid(row=i,column=j,padx=2,pady=2,ipadx=5,ipady=5) > mainloop() > > It shows up on my screen as rectangular (non-square) shaped. What do I have > to do to make it appear in a square-shaped form (i.e. with Label height & > width to be equal on the sceen)? The problem is that you can't do that with Label widgets, because width and height is relative to the font used. The units of width is caracters, no pixels, and the units of height is lines, no pixels. As a probe of concept, change Label for Canvas and eliminate the parameter "text=str(k)" hth From klappnase at web.de Wed Jul 21 22:28:15 2010 From: klappnase at web.de (Michael Lange) Date: Wed, 21 Jul 2010 22:28:15 +0200 Subject: [Tkinter-discuss] Widget to appear square-shaped on screen... In-Reply-To: References: <29216127.post@talk.nabble.com> Message-ID: <20100721222815.5a3bc556.klappnase@web.de> Hi, On Tue, 20 Jul 2010 14:55:51 -0300 Roberto Gomez wrote: > GKalman wrote: > > I'm trying to make a square-shaped board, something like this: > > > > from Tkinter import * > > > > root = Tk() > > w=[] > > for k in range(9): > > i=k/3 > > j=k%3 > > w.append(Label(root,text=str(k),bg="red",width=5,height=5)) > > w[k].grid(row=i,column=j,padx=2,pady=2,ipadx=5,ipady=5) > > mainloop() > > > > It shows up on my screen as rectangular (non-square) shaped. What > > do I have to do to make it appear in a square-shaped form (i.e. > > with Label height & width to be equal on the sceen)? > > The problem is that you can't do that with Label widgets, because > width and height is relative to the font used. The units of width is > caracters, no pixels, and the units of height is lines, no pixels. > As a probe of concept, change Label for Canvas and eliminate the > parameter "text=str(k)" > hth > Actually you can do this very easily with a Label, the trick is to use an empty image, so width and height will be measured in pixels : >>> from Tkinter import * >>> root = Tk() >>> i = PhotoImage() >>> l = Label(root, text='foo', image=i, width=200, height=200, compound='center', relief='solid') >>> l.pack(padx=10, pady=10) Using the empty image it should not matter if you set compound to 'center' or something else, but it must be defined somehow, otherwise you will not see the Label's text. I hope this helps Michael From kalman_g at msn.com Thu Jul 22 03:20:27 2010 From: kalman_g at msn.com (GKalman) Date: Wed, 21 Jul 2010 18:20:27 -0700 (PDT) Subject: [Tkinter-discuss] Widget to appear square-shaped on screen... In-Reply-To: <20100721222815.5a3bc556.klappnase@web.de> References: <29216127.post@talk.nabble.com> <20100721222815.5a3bc556.klappnase@web.de> Message-ID: <29232401.post@talk.nabble.com> Thanks to all. They were very useful. _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org http://mail.python.org/mailman/listinfo/tkinter-discuss -- View this message in context: http://old.nabble.com/Widget-to-appear-square-shaped-on-screen...-tp29216127p29232401.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From petr0ff at seznam.cz Sat Jul 24 12:41:21 2010 From: petr0ff at seznam.cz (petroff) Date: Sat, 24 Jul 2010 03:41:21 -0700 (PDT) Subject: [Tkinter-discuss] add/remove button in runtime Message-ID: <29254236.post@talk.nabble.com> I want to allow changing in (sorted) list of buttons: self.ADRbuttons=[B1,B2...] REMOVE => button.destroy (it works correctly) ADD is a problem; I don't know how to insert button on correct location in button panel (pack method) [part of code] class ADRButton(Button): def __init__(self, apObj, data, index, master=None, **d): txt = data[index]["jmeno"] Button.__init__(self, master,text=txt,command=lambda x=index: apObj.selectADR(x), **d) self.pack(fill=X,padx=5, pady=2) class App(Tk): def loadADR(self): self.datADR = (...) ### SORTED LIST, I'm going to use PICKLE for load/save ### def __init__(self, master=None): Tk.__init__(self, master) self.loadADR() self.selectedADR = -1 .... fADR=Frame(self,width=90,bg="#707070") fADR.pack_propagate(0) fADR.pack(side=LEFT,fill=Y) Frame(fADR,height=20,bg="#707070").pack(side=TOP,fill=X,fill=Y) self.ADRbuttons=[] for i in range(len(self.datADR)): self.ADRbuttons.append(ADRButton(self,self.datADR,i,fADR, activebackground="white", anchor='w', justify=LEFT)) .... -- View this message in context: http://old.nabble.com/add-remove-button-in-runtime-tp29254236p29254236.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From petr0ff at seznam.cz Sat Jul 24 12:41:21 2010 From: petr0ff at seznam.cz (petroff) Date: Sat, 24 Jul 2010 03:41:21 -0700 (PDT) Subject: [Tkinter-discuss] add/remove button in runtime Message-ID: <29254237.post@talk.nabble.com> I want to allow changing in (sorted) list of buttons: self.ADRbuttons=[B1,B2...] REMOVE => button.destroy (it works correctly) ADD is a problem; I don't know how to insert button on correct location in button panel (pack method) [part of code] class ADRButton(Button): def __init__(self, apObj, data, index, master=None, **d): txt = data[index]["jmeno"] Button.__init__(self, master,text=txt,command=lambda x=index: apObj.selectADR(x), **d) self.pack(fill=X,padx=5, pady=2) class App(Tk): def loadADR(self): self.datADR = (...) ### SORTED LIST, I'm going to use PICKLE for load/save ### def __init__(self, master=None): Tk.__init__(self, master) self.loadADR() self.selectedADR = -1 .... fADR=Frame(self,width=90,bg="#707070") fADR.pack_propagate(0) fADR.pack(side=LEFT,fill=Y) Frame(fADR,height=20,bg="#707070").pack(side=TOP,fill=X,fill=Y) self.ADRbuttons=[] for i in range(len(self.datADR)): self.ADRbuttons.append(ADRButton(self,self.datADR,i,fADR, activebackground="white", anchor='w', justify=LEFT)) .... -- View this message in context: http://old.nabble.com/add-remove-button-in-runtime-tp29254237p29254237.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From klappnase at web.de Sun Jul 25 20:44:11 2010 From: klappnase at web.de (Michael Lange) Date: Sun, 25 Jul 2010 20:44:11 +0200 Subject: [Tkinter-discuss] add/remove button in runtime In-Reply-To: <29254237.post@talk.nabble.com> References: <29254237.post@talk.nabble.com> Message-ID: <20100725204411.fa60176f.klappnase@web.de> Hi, On Sat, 24 Jul 2010 03:41:21 -0700 (PDT) petroff wrote: > > I want to allow changing in (sorted) list of buttons: > self.ADRbuttons=[B1,B2...] > REMOVE => button.destroy (it works correctly) > ADD is a problem; I don't know how to insert button on correct > location in button panel (pack method) This sounds like the grid() geometry manager is the perfect tool for you, is there any special reason why you want to use pack() instead? With grid() you could easily do something like: for i in range(len(self.datADR)): new = Button(self) new.grid(row=0, column=i) self.ADRbuttons.append(new) If you want to change the location of a button later, simply call grid() again with the new row and column. I hope this helps Michael From rowen at uw.edu Mon Jul 26 20:41:55 2010 From: rowen at uw.edu (Russell E. Owen) Date: Mon, 26 Jul 2010 11:41:55 -0700 Subject: [Tkinter-discuss] add/remove button in runtime References: <29254237.post@talk.nabble.com> Message-ID: In article <29254237.post at talk.nabble.com>, petroff wrote: > I want to allow changing in (sorted) list of buttons: > self.ADRbuttons=[B1,B2...] > REMOVE => button.destroy (it works correctly) > ADD is a problem; I don't know how to insert button on correct location in > button panel (pack method) >... You could try the "before" option to the pack method. I've not used it myself and I'm not sure it'll work. Personally I would lay out all the buttons every time you remove or insert one. If you use the grid manager (which I usually use because it is more flexible than pack): - keep the buttons in a collection, e.g.: a list of (button_name, button) so you can sort it by calling the sort method - to add one, ungrid all in the current collection with grid_remove or grid_forget (the latter is fine in this case since you're not going to regrid it in the same place) - add the new button to the collection - grid all buttons in the collection -- Russell From michael.odonnell at uam.es Tue Jul 27 00:42:22 2010 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Tue, 27 Jul 2010 00:42:22 +0200 Subject: [Tkinter-discuss] add/remove button in runtime In-Reply-To: References: <29254237.post@talk.nabble.com> Message-ID: The -before option in pack does in fact work, and would save time regenerating all the widgets. Mick On Mon, Jul 26, 2010 at 8:41 PM, Russell E. Owen wrote: > In article <29254237.post at talk.nabble.com>, petroff > wrote: > >> I want to allow changing in (sorted) list of buttons: >> self.ADRbuttons=[B1,B2...] >> REMOVE => button.destroy (it works correctly) >> ADD is a problem; I don't know how to insert button on correct location in >> button panel (pack method) >>... > > You could try the "before" option to the pack method. I've not used it > myself and I'm not sure it'll work. > > Personally I would lay out all the buttons every time you remove or > insert one. If you use the grid manager (which I usually use because it > is more flexible than pack): > - keep the buttons in a collection, e.g.: a list of > ? (button_name, button) so you can sort it by calling the sort method > - to add one, ungrid all in the current collection with grid_remove or > grid_forget (the latter is fine in this case since you're not going to > regrid it in the same place) > - add the new button to the collection > - grid all buttons in the collection > > -- Russell > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss >