From acb at incident.com Sat Jun 6 07:17:56 2009 From: acb at incident.com (Art Botterell) Date: Fri, 5 Jun 2009 22:17:56 -0700 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? Message-ID: Hi, new Python/Tkinter adopter here! I'm building a little screen display to show status of a remote device (a radio scanner) in an MVC pattern. In the top-level "view" GUI object I'm updating the text in three Entry fields and the background color of a Frame, all at a rate of about five cycles per second. Works fine except it leaks memory at a rate of between 1-2K per second. As best I can tell the problem seems to be down in Tkinter: I can pass- out the set() calls to the StringVars and the color update and leave everything else and my memory consumption stablizes. I can also induce a leak by making get()s. I tried bypassing the StringVar mechanism and doing delete()/insert() directly on the Entry widgets... that didn't seem to solve it either. Googling around I can see that there've been various memory leak issues in past history, but I don't see any open issues with 8.5.7 and/ or Python 2.6.2. So I wonder if maybe I'm just making a noobish mistake in my own code (please see below.) I'm admitting my helplessness and pleading for help. TIA! - Art #! /usr/bin/env python ''' Created on June 5, 2009 @author: acb ''' from Tkinter import * import tkFont import time import Controller import threading import sys import signal class Display: def shutdown(foo): sys.exit() def __init__(self, root): # define display fonts self.sans1 = tkFont.Font( family="sanserif", size=24) self.sans2 = tkFont.Font( family="sanserif", size=12) # shutdown on window close and on control-c root.protocol("WM_DELETE_WINDOW", self.shutdown) def exit_handler( signal, frame ): self.shutdown() signal.signal(signal.SIGINT, exit_handler) # Set up the display frame and fields self.toppad = Frame(root, height=4) self.toppad.pack() self.display = Frame(root) self.indisplay = Frame(self.display, background="#ffffff") self.spacer = Frame(self.indisplay, height=5) self.spacer.pack(expand=YES) self.freq = Entry(self.indisplay) self.freqString = StringVar() self.freq.config(justify=CENTER, font=self.sans2, borderwidth=0, textvariable=self.freqString) self.freq.pack(padx=10, pady=5) self.label = Entry(self.indisplay) self.labelString = StringVar() self.label.config(justify=CENTER, font=self.sans1, borderwidth=0, width=12, textvariable=self.labelString) self.label.pack(padx=10, pady=5) self.object = Entry(self.indisplay) self.objectString = StringVar() self.object.config(justify=CENTER, font=self.sans2, borderwidth=0, textvariable=self.objectString) self.object.pack(padx=10, pady=5) self.spacer = Frame(self.indisplay, height=5) self.spacer.pack(expand=YES) self.indisplay.config() self.indisplay.pack( fill=BOTH, padx=2, pady=2 ) self.display.pack(fill=BOTH, padx=5) # Set up controls self.control = Canvas(root) self.keycode = 0 self.manBtn = Button(self.control, text="Manual") self.manBtn.pack(side=LEFT,padx=20) self.manBtn['command']=lambda: self.keyset(3) self.upBtn = Button(self.control, text="Up") self.upBtn.pack(side=LEFT,expand=YES,padx=10) self.upBtn['command']=lambda: self.keyset(7) self.dnBtn = Button(self.control, text="Dn") self.dnBtn.pack(side=LEFT,expand=YES,padx=10) self.dnBtn['command']=lambda: self.keyset(9) self.scnBtn = Button(self.control, text="Scan") self.scnBtn.pack(side=RIGHT,padx=20) self.scnBtn['command']=lambda: self.keyset(15) self.control.pack(fill=X, ipady=2, pady=4) self.controller = Controller.Controller(self) # command to send a keystroke to the scanner def keyset(self, value): self.controller.send_key(value) # commands to update the display fields (called from the controller) def set_freq(self, text): self.freqString.set(text) def set_label(self, text): self.labelString.set(text) def set_object(self, text): self.objectString.set(text) def set_color(self, text): self.display['background']=text root = Tk() disp = Display(root) root.wm_title("PSR-600 Remote v0.4") root.mainloop() From acb at incident.com Sat Jun 6 17:21:57 2009 From: acb at incident.com (Art Botterell) Date: Sat, 6 Jun 2009 08:21:57 -0700 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: References: Message-ID: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> > PS - I also switched from Entry to Label widgets... but saw the same memory-gobbling behavior. - Art From ggpolo at gmail.com Sat Jun 6 20:30:16 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Sat, 6 Jun 2009 15:30:16 -0300 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> Message-ID: On Sat, Jun 6, 2009 at 12:21 PM, Art Botterell wrote: >> > > PS - I also switched from Entry to Label widgets... but saw the same > memory-gobbling behavior. > Now I ask you to reduce the sample you posted above. Or do you really need all those lines to notice the memory leak ? I didn't look at it yet, but I (and I believe others too) would prefer to look at it only if you are sure that some shorter sample can't reproduce the problem. > - Art > -- -- Guilherme H. Polo Goncalves From ggpolo at gmail.com Sat Jun 6 20:33:30 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Sat, 6 Jun 2009 15:33:30 -0300 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> Message-ID: On Sat, Jun 6, 2009 at 3:30 PM, Guilherme Polo wrote: > On Sat, Jun 6, 2009 at 12:21 PM, Art Botterell wrote: >>> >> >> PS - I also switched from Entry to Label widgets... but saw the same >> memory-gobbling behavior. >> > > Now I ask you to reduce the sample you posted above. Or do you really > need all those lines to notice the memory leak ? I didn't look at it > yet, but I (and I believe others too) ?would prefer to look at it only > if you are sure that some shorter sample can't reproduce the problem. Oh well, I didn't resist :) I looked at it, but it is missing the important part: the Controller module code. I don't see anything else on your example that would cause the problem but this Controller. -- -- Guilherme H. Polo Goncalves From acb at incident.com Sat Jun 6 22:11:25 2009 From: acb at incident.com (Art Botterell) Date: Sat, 6 Jun 2009 13:11:25 -0700 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> Message-ID: I thought my description was fairly concise... the code was really just along for reference. But if I'm asking for too much effort please never mind, I'll just switch to pyglet or something else. I just thought somebody else might be facing the same challenge. - Art On Jun 6, 2009, at 6/6/09 11:30 AM, Guilherme Polo wrote: > On Sat, Jun 6, 2009 at 12:21 PM, Art Botterell > wrote: >>> >> >> PS - I also switched from Entry to Label widgets... but saw the same >> memory-gobbling behavior. >> > > Now I ask you to reduce the sample you posted above. Or do you really > need all those lines to notice the memory leak ? I didn't look at it > yet, but I (and I believe others too) would prefer to look at it only > if you are sure that some shorter sample can't reproduce the problem. > >> - Art >> > > > > -- > -- Guilherme H. Polo Goncalves From acb at incident.com Sat Jun 6 22:21:55 2009 From: acb at incident.com (Art Botterell) Date: Sat, 6 Jun 2009 13:21:55 -0700 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> Message-ID: <47D9B39B-A01F-4996-92FB-22B1A0339D5B@incident.com> On Jun 6, 2009, at 6/6/09 11:33 AM, Guilherme Polo wrote: > Oh well, I didn't resist :) > I looked at it, but it is missing the important part: the Controller > module code. I don't see anything else on your example that would > cause the problem but this Controller. OK, so now the problem is that I didn't post ENOUGH code! ;-) Controller just calls in with strings, roughly ten times a second, via the set_freq() etc. calls. I've tried locally-generating those strings, too, but it's only when I modify the Label text, one way or another, that I start bleeding memory. (And I've also done a Pyglet version of the display now, using the exact same Controller code... it starts out larger in memory, but it stays the same size. So I'm inclined to suspect the problem is down in Tkinter or below, not in my ap code. Sorry.) - Art From ggpolo at gmail.com Sat Jun 6 22:38:35 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Sat, 6 Jun 2009 17:38:35 -0300 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> Message-ID: On Sat, Jun 6, 2009 at 5:11 PM, Art Botterell wrote: > I thought my description was fairly concise... the code was really just > along for reference. Yet you didn't include code that leak memory. It could be one line long and leak memory, or it could be 10k lines long and contain no memory leaks, it is not really about the size of what you post. >?But if I'm asking for too much effort please never > mind, I'll just switch to pyglet or something else. ?I just thought somebody > else might be facing the same challenge. > Right, that is a good way to solve things. > - Art -- -- Guilherme H. Polo Goncalves From ggpolo at gmail.com Sat Jun 6 22:40:20 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Sat, 6 Jun 2009 17:40:20 -0300 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: <47D9B39B-A01F-4996-92FB-22B1A0339D5B@incident.com> References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> <47D9B39B-A01F-4996-92FB-22B1A0339D5B@incident.com> Message-ID: On Sat, Jun 6, 2009 at 5:21 PM, Art Botterell wrote: > On Jun 6, 2009, at 6/6/09 11:33 AM, Guilherme Polo wrote: >> >> Oh well, I didn't resist :) >> I looked at it, but it is missing the important part: the Controller >> module code. I don't see anything else on your example that would >> cause the problem but this Controller. > > OK, so now the problem is that I didn't post ENOUGH code! ;-) Or ENOUGH code that matters. > > Controller just calls in with strings, roughly ten times a second, via the > set_freq() etc. calls. ?I've tried locally-generating those strings, too, > but it's only when I modify the Label text, one way or another, that I start > bleeding memory. > Your code can't be executed, I doubt you will get good answers with the code you posted earlier. Please, include a code that runs and that also contains the described problem. > > - Art -- -- Guilherme H. Polo Goncalves From acb at incident.com Sat Jun 6 22:51:29 2009 From: acb at incident.com (Art Botterell) Date: Sat, 6 Jun 2009 13:51:29 -0700 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> <47D9B39B-A01F-4996-92FB-22B1A0339D5B@incident.com> Message-ID: On Jun 6, 2009, at 6/6/09 1:40 PM, Guilherme Polo wrote: > Please, include a code that runs and that also contains the > described problem. Not sure how to be sure of meeting your requirements short of posting my entire application plus my full Python/Tk/Tcl/OS X stack... and shipping you my hardware to boot. (I think you assume the problem is in my ap code, but I'm not sure that's the only possibility.) So I guess I'll just have to muddle through, unless anyone else has something constructive to offer. Thanks! - Art From Cameron at phaseit.net Sat Jun 6 23:40:21 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Sat, 6 Jun 2009 21:40:21 +0000 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> <47D9B39B-A01F-4996-92FB-22B1A0339D5B@incident.com> Message-ID: <20090606214021.GA15856@lairds.us> On Sat, Jun 06, 2009 at 01:51:29PM -0700, Art Botterell wrote: . . . > On Jun 6, 2009, at 6/6/09 1:40 PM, Guilherme Polo wrote: > >Please, include a code that runs and that also contains the > >described problem. > > Not sure how to be sure of meeting your requirements short of posting > my entire application plus my full Python/Tk/Tcl/OS X stack... and > shipping you my hardware to boot. (I think you assume the problem is > in my ap code, but I'm not sure that's the only possibility.) > > So I guess I'll just have to muddle through, unless anyone else has > something constructive to offer. . . . There's probably a leak in your code. It's possible Tkinter itself leaks; if that can be confirmed, though, it's almost certain it'll quickly be fixed. Pyglet is no guarantee of better results. Experienced developers generally can find leaks as reproducible as yours seems to be. Leaks are subtle, though, and Guilherme is absolutely right in advising you that help depends on your specific implementation. You could hire someone to come look at your system and spot the leak. That probably can be done for a modest charge. To pursue this on your own, you need to do what Guilherme describes: make a small code sample. I entirely understand that, right now, you can only exhibit the symptom in your entire, properly-hosted-on-the-right-OS, application. To reduce such a symptom to a small example is a major element of programming technique. You can practice the skill, or pay someone else to lead the investigation, or put up with the leak. Realistic alternatives are few. There *are* common leak-producing errors with Entry and Label, but they're hard to describe in the abstract. From acb at incident.com Sun Jun 7 00:12:45 2009 From: acb at incident.com (Art Botterell) Date: Sat, 6 Jun 2009 15:12:45 -0700 Subject: [Tkinter-discuss] Leak with Entry on Mac ( 8.5.7 / 2.6.2 )? In-Reply-To: <20090606214021.GA15856@lairds.us> References: <89454FD5-04D1-4E2C-86F9-CA922B58EDA5@incident.com> <47D9B39B-A01F-4996-92FB-22B1A0339D5B@incident.com> <20090606214021.GA15856@lairds.us> Message-ID: <49241E9B-D479-45D1-8822-0864845FEAFE@incident.com> On Jun 6, 2009, at 6/6/09 2:40 PM, Cameron Laird wrote: > You can practice the skill, or pay someone else to lead the > investigation, or put up with the leak. Realistic > alternatives are few. Or I can simply pick a different tool, which is looking like the most productive approach. I usually do all my UI work in Flex, or failing that in Swing. Python is really just an experiment for me, one that had been quite pleasant until I attempted the GUI bit. > There *are* common leak-producing errors with Entry and Label, but > they're hard to describe in the abstract. And I'm assuming that nobody's spotted me committing one of them in the code I've posted... which was really all I was asking. - Art From bob at passcal.nmt.edu Sun Jun 7 19:52:30 2009 From: bob at passcal.nmt.edu (Bob Greschke) Date: Sun, 7 Jun 2009 11:52:30 -0600 Subject: [Tkinter-discuss] Adding to a Listbox In-Reply-To: <20090526202353.7b7f01c8.klappnase@web.de> References: <20090526202353.7b7f01c8.klappnase@web.de> Message-ID: <061E66C7-6A99-4974-BB26-BD4EE73D7AE6@passcal.nmt.edu> On May 26, 2009, at 12:23, Michael Lange wrote: > Hi Bob, > > On Tue, 26 May 2009 10:31:26 -0600 > Bob Greschke wrote: > >> I'd like to add (i.e. use the Command key on a >> Mac) event handling to a Listbox so that it behaves just like the >> "built-in" behavior (selecting/deselecting >> individual items when the selectmode is EXTENDED). What should the >> bind statement call to do that? Can it be done through something >> like an option_add so it applies to all listboxes in an application? >> > > I think > > root = Tk() > root.bind_class('Listbox', '', > root.bind_class('Listbox', '') ) > > should do the trick. > > Regards > > Michael Hmmm. This didn't seem to do anything (not even an error message). After some more fooling around it looks like the the Command key isn't acknowledged at all on my Mac (either running apps on a Sun via ssh, or running them directly on my Mac). I'm running "our own" version of Python/Tkinter( so we don't get the Aqua-based version), and also the XQuartz guys' version of X11 (I messed with the keyboard preferences in there, but it didn't seem to do anything). The build of our Python/ Tkinter may have something to do with it. I'll check with the guys that make our package. There might be some switch that needs to be flipped. ...but now I do see how to use .bind_class...so I still came out of this more dangerous than I was. :) Thanks! Bob From kw at codebykevin.com Sun Jun 7 21:25:50 2009 From: kw at codebykevin.com (Kevin Walzer) Date: Sun, 07 Jun 2009 15:25:50 -0400 Subject: [Tkinter-discuss] Adding to a Listbox In-Reply-To: <061E66C7-6A99-4974-BB26-BD4EE73D7AE6@passcal.nmt.edu> References: <20090526202353.7b7f01c8.klappnase@web.de> <061E66C7-6A99-4974-BB26-BD4EE73D7AE6@passcal.nmt.edu> Message-ID: <4A2C143E.5070701@codebykevin.com> Bob Greschke wrote: > > Hmmm. This didn't seem to do anything (not even an error message). > After some more fooling around it looks like the the Command key isn't > acknowledged at all on my Mac (either running apps on a Sun via ssh, or > running them directly on my Mac). I'm running "our own" version of > Python/Tkinter( so we don't get the Aqua-based version), and also the > XQuartz guys' version of X11 (I messed with the keyboard preferences in > there, but it didn't seem to do anything). The build of our > Python/Tkinter may have something to do with it. I'll check with the > guys that make our package. There might be some switch that needs to be > flipped. > The Command key isn't supported under X11--the Control key is. Command is a Mac (Aqua) -specific keysym. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From bob at passcal.nmt.edu Sun Jun 7 21:39:35 2009 From: bob at passcal.nmt.edu (Bob Greschke) Date: Sun, 7 Jun 2009 13:39:35 -0600 Subject: [Tkinter-discuss] Adding to a Listbox In-Reply-To: <4A2C143E.5070701@codebykevin.com> References: <20090526202353.7b7f01c8.klappnase@web.de> <061E66C7-6A99-4974-BB26-BD4EE73D7AE6@passcal.nmt.edu> <4A2C143E.5070701@codebykevin.com> Message-ID: <2ED2EEC1-BBFF-4D7C-A32F-8EFA64232084@passcal.nmt.edu> On Jun 7, 2009, at 13:25, Kevin Walzer wrote: > Bob Greschke wrote: > >> Hmmm. This didn't seem to do anything (not even an error >> message). After some more fooling around it looks like the the >> Command key isn't acknowledged at all on my Mac (either running >> apps on a Sun via ssh, or running them directly on my Mac). I'm >> running "our own" version of Python/Tkinter( so we don't get the >> Aqua-based version), and also the XQuartz guys' version of X11 (I >> messed with the keyboard preferences in there, but it didn't seem >> to do anything). The build of our Python/Tkinter may have >> something to do with it. I'll check with the guys that make our >> package. There might be some switch that needs to be flipped. >> > > The Command key isn't supported under X11--the Control key is. > Command is a Mac (Aqua) -specific keysym. > -- > Kevin Walzer > Code by Kevin > http://www.codebykevin.com > I'll buy that. The Command key (and the Option key) are listed in Grayson as valid modifiers, so I thought they would work since the book came out way back when (2000). Thanks! Bob From akadzban at iit.edu Wed Jun 10 22:19:14 2009 From: akadzban at iit.edu (Adam Kadzban) Date: Wed, 10 Jun 2009 15:19:14 -0500 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton Message-ID: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> Hi, I'm having some problems with my Checkbuttons. I'm giving them IntVars to bind to, but there seems to be no relationship between the IntVars and the buttons. This is the first time I've had problems with this, I've used IntVars with Checkbuttons in the past with no such trouble. I have the main part of the GUI (which has Checkbuttons that behave normally), with a menu option to create another window for some "advanced options". The code for this window is in its own class, which takes a list of options as parameters and then has some check boxes and entry boxes so you can change the option list. Here's the relevant code: ... self.tVar = IntVar() ... self.tempbutton = Checkbutton(self.tophalf,variable=self.tVar,text="Calculate temperature") ... When I try the program with this code, I can check/uncheck the boxes, but tVar never change (I printed out their values, they stay 0). I also tried coding in button selection (e.g. self.tempbutton.select()), but tVar never changes. I also tried making some functions, and binding them to the checkbutton: self.tempbutton = Checkbutton(self.tophalf,variable=self.tVar,text="Calculate temperature",command=self.checkTemp) ... def checkTemp(self): if self.tVar.get() == 1: self.tempbutton.select() else: self.tempbutton.deselect() ... Having that, though, doesn't let me "check" the button (I'm guessing because tVar never gets set to 1, it always goes to deselect). Anyone have any ideas why this is happening? I've been banging my head against a wall here, and I rewrote the whole class thinking maybe it was something funny with scoping, but as far as I can tell everything is ok. I must be missing something... Thanks, Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Wed Jun 10 22:50:38 2009 From: klappnase at web.de (Michael Lange) Date: Wed, 10 Jun 2009 22:50:38 +0200 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton In-Reply-To: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> References: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> Message-ID: <20090610225038.9e98d61f.klappnase@web.de> Hi Adam, On Wed, 10 Jun 2009 15:19:14 -0500 Adam Kadzban wrote: (...) > boxes and entry boxes so you can change the option list. Here's the > relevant code: > > ... > self.tVar = IntVar() > ... > self.tempbutton = > Checkbutton(self.tophalf,variable=self.tVar,text="Calculate > temperature") ... > > When I try the program with this code, I can check/uncheck the boxes, > but tVar never change (I printed out their values, they stay 0). I > also tried coding in button selection (e.g. self.tempbutton.select > ()), but tVar never changes. I cannot reproduce this here, maybe it depends on the OS or the Tk version in use. Just a guess: have you tried to explicitely define onvalue=1 and offvalue=0 in the Checkbutton constructor ? Michael > > I also tried making some functions, and binding them to the > checkbutton: self.tempbutton = > Checkbutton(self.tophalf,variable=self.tVar,text="Calculate > temperature",command=self.checkTemp) > ... > def checkTemp(self): > if self.tVar.get() == 1: > self.tempbutton.select() > else: > self.tempbutton.deselect() > ... > Having that, though, doesn't let me "check" the button (I'm guessing > because tVar never gets set to 1, it always goes to deselect). > > Anyone have any ideas why this is happening? I've been banging my > head against a wall here, and I rewrote the whole class thinking > maybe it was something funny with scoping, but as far as I can tell > everything is ok. I must be missing something... > > Thanks, > Adam > From akadzban at iit.edu Wed Jun 10 23:05:58 2009 From: akadzban at iit.edu (Adam Kadzban) Date: Wed, 10 Jun 2009 16:05:58 -0500 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton In-Reply-To: <20090610225038.9e98d61f.klappnase@web.de> References: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> <20090610225038.9e98d61f.klappnase@web.de> Message-ID: <823ecc3a0906101405p5b4e5a2fved1f860a7510c8c@mail.gmail.com> On Wed, Jun 10, 2009 at 3:50 PM, Michael Lange wrote: > Hi Adam, > > On Wed, 10 Jun 2009 15:19:14 -0500 > Adam Kadzban wrote: > > (...) > > boxes and entry boxes so you can change the option list. Here's the > > relevant code: > > > > ... > > self.tVar = IntVar() > > ... > > self.tempbutton = > > Checkbutton(self.tophalf,variable=self.tVar,text="Calculate > > temperature") ... > > > > When I try the program with this code, I can check/uncheck the boxes, > > but tVar never change (I printed out their values, they stay 0). I > > also tried coding in button selection (e.g. self.tempbutton.select > > ()), but tVar never changes. > > I cannot reproduce this here, maybe it depends on the OS or the Tk > version in use. Just a guess: have you tried to explicitely define > onvalue=1 and offvalue=0 in the Checkbutton constructor ? > > Michael I'm on Ubuntu 9.04, with Python 2.5.2 and the latest version of python-tk, at least according to aptitude. And yes, I've tried that, didn't work. Adam > > > > > > I also tried making some functions, and binding them to the > > checkbutton: self.tempbutton = > > Checkbutton(self.tophalf,variable=self.tVar,text="Calculate > > temperature",command=self.checkTemp) > > ... > > def checkTemp(self): > > if self.tVar.get() == 1: > > self.tempbutton.select() > > else: > > self.tempbutton.deselect() > > ... > > Having that, though, doesn't let me "check" the button (I'm guessing > > because tVar never gets set to 1, it always goes to deselect). > > > > Anyone have any ideas why this is happening? I've been banging my > > head against a wall here, and I rewrote the whole class thinking > > maybe it was something funny with scoping, but as far as I can tell > > everything is ok. I must be missing something... > > > > Thanks, > > Adam > > > _______________________________________________ > 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 akadzban at iit.edu Thu Jun 11 00:42:11 2009 From: akadzban at iit.edu (Adam Kadzban) Date: Wed, 10 Jun 2009 17:42:11 -0500 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton In-Reply-To: <4A302EF9.1080702@velseis.com.au> References: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> <4A302EF9.1080702@velseis.com.au> Message-ID: <823ecc3a0906101542i4e91b3er38838089df1df47b@mail.gmail.com> On Wed, Jun 10, 2009 at 5:08 PM, John McMonagle wrote: > Adam Kadzban wrote: > > > I have the main part of the GUI (which has Checkbuttons that behave > > normally), with a menu option to create another window for some > > "advanced options". The code for this window is in its own class, which > > takes a list of options as parameters and then has some check boxes and > > entry boxes so you can change the option list. Here's the relevant code: > > > > It's not all that relevant to me. Try to reduce your problem to the > minimal code which exhibits the indicated behaviour. > > All I can think of, without seeing your offending code, is maybe the > IntVar or the Checkbutton is being garbage collected somehow. > > Regards, > > John > Stripped down fg.py: http://pastebin.com/m4c32483e Stripped down aow.py: http://pastebin.com/m4ab77b3d This still exhibits the behavior for me, is anyone else getting it? Also, just realized this laptop is running Ubuntu 8.10, not 9.04, if that makes a difference. -Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: From akadzban at iit.edu Thu Jun 11 00:51:21 2009 From: akadzban at iit.edu (Adam Kadzban) Date: Wed, 10 Jun 2009 17:51:21 -0500 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton In-Reply-To: <823ecc3a0906101542i4e91b3er38838089df1df47b@mail.gmail.com> References: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> <4A302EF9.1080702@velseis.com.au> <823ecc3a0906101542i4e91b3er38838089df1df47b@mail.gmail.com> Message-ID: <823ecc3a0906101551k258a616fx114120d839f8bfaa@mail.gmail.com> On Wed, Jun 10, 2009 at 5:42 PM, Adam Kadzban wrote: > > > On Wed, Jun 10, 2009 at 5:08 PM, John McMonagle > wrote: > >> Adam Kadzban wrote: >> >> > I have the main part of the GUI (which has Checkbuttons that behave >> > normally), with a menu option to create another window for some >> > "advanced options". The code for this window is in its own class, which >> > takes a list of options as parameters and then has some check boxes and >> > entry boxes so you can change the option list. Here's the relevant >> code: >> > >> >> It's not all that relevant to me. Try to reduce your problem to the >> minimal code which exhibits the indicated behaviour. >> >> All I can think of, without seeing your offending code, is maybe the >> IntVar or the Checkbutton is being garbage collected somehow. >> >> Regards, >> >> John >> > > > Stripped down fg.py: http://pastebin.com/m4c32483e > Stripped down aow.py: http://pastebin.com/m4ab77b3d > > This still exhibits the behavior for me, is anyone else getting it? Also, > just realized this laptop is running Ubuntu 8.10, not 9.04, if that makes a > difference. > > -Adam > Oddly enough, this works: http://pastebin.com/m5c9cbc1b I suppose I could just change all my code to that... -Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmcmonagle at velseis.com.au Thu Jun 11 00:08:57 2009 From: jmcmonagle at velseis.com.au (John McMonagle) Date: Thu, 11 Jun 2009 08:08:57 +1000 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton In-Reply-To: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> References: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> Message-ID: <4A302EF9.1080702@velseis.com.au> Adam Kadzban wrote: > I have the main part of the GUI (which has Checkbuttons that behave > normally), with a menu option to create another window for some > "advanced options". The code for this window is in its own class, which > takes a list of options as parameters and then has some check boxes and > entry boxes so you can change the option list. Here's the relevant code: > It's not all that relevant to me. Try to reduce your problem to the minimal code which exhibits the indicated behaviour. All I can think of, without seeing your offending code, is maybe the IntVar or the Checkbutton is being garbage collected somehow. Regards, John From ggpolo at gmail.com Thu Jun 11 02:14:51 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 10 Jun 2009 21:14:51 -0300 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton In-Reply-To: <823ecc3a0906101542i4e91b3er38838089df1df47b@mail.gmail.com> References: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> <4A302EF9.1080702@velseis.com.au> <823ecc3a0906101542i4e91b3er38838089df1df47b@mail.gmail.com> Message-ID: On Wed, Jun 10, 2009 at 7:42 PM, Adam Kadzban wrote: > > > On Wed, Jun 10, 2009 at 5:08 PM, John McMonagle > wrote: >> >> Adam Kadzban wrote: >> >> > I have the main part of the GUI (which has Checkbuttons that behave >> > normally), with a menu option to create another window for some >> > "advanced options". ?The code for this window is in its own class, which >> > takes a list of options as parameters and then has some check boxes and >> > entry boxes so you can change the option list. ?Here's the relevant >> > code: >> > >> >> It's not all that relevant to me. ?Try to reduce your problem to the >> minimal code which exhibits the indicated behaviour. >> >> All I can think of, without seeing your offending code, is maybe the >> IntVar or the Checkbutton is being garbage collected somehow. >> >> Regards, >> >> John > > > Stripped down fg.py:? http://pastebin.com/m4c32483e > Stripped down aow.py:? http://pastebin.com/m4ab77b3d > > This still exhibits the behavior for me, is anyone else getting it? It happens to work for me right now, but what you are doing is just plain wrong. Inside this fg.py you are instantiating a Tk class, which creates a Tcl interpreter and loads the tk module (since you didn't tell it to not load tk). Then when you instantiate this class "window" inside aow you create another Tcl interpreter by instantiating the Tk class again (you are not supposed to create multiple Tcl interpreters to show multiple windows, instead, instantiate Toplevel multiple times). Then you proceed to create a checkbutton which has this new Tcl interpreter as the master, but you create the Tcl variable using the previously created master. So, you are trying to use a variable created in a Tcl interpreter, with a widget created in a different interpreter and there is nothing in Tkinter that guarantees you that this will end up working. Hope it helps you, and others, to notice how this is not going to work properly. > Also, > just realized this laptop is running Ubuntu 8.10, not 9.04, if that makes a > difference. > > -Adam -- -- Guilherme H. Polo Goncalves From ggpolo at gmail.com Thu Jun 11 02:16:52 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 10 Jun 2009 21:16:52 -0300 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton In-Reply-To: <823ecc3a0906101551k258a616fx114120d839f8bfaa@mail.gmail.com> References: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> <4A302EF9.1080702@velseis.com.au> <823ecc3a0906101542i4e91b3er38838089df1df47b@mail.gmail.com> <823ecc3a0906101551k258a616fx114120d839f8bfaa@mail.gmail.com> Message-ID: On Wed, Jun 10, 2009 at 7:51 PM, Adam Kadzban wrote: > On Wed, Jun 10, 2009 at 5:42 PM, Adam Kadzban wrote: >> >> >> On Wed, Jun 10, 2009 at 5:08 PM, John McMonagle >> wrote: >>> >>> Adam Kadzban wrote: >>> >>> > I have the main part of the GUI (which has Checkbuttons that behave >>> > normally), with a menu option to create another window for some >>> > "advanced options". ?The code for this window is in its own class, >>> > which >>> > takes a list of options as parameters and then has some check boxes and >>> > entry boxes so you can change the option list. ?Here's the relevant >>> > code: >>> > >>> >>> It's not all that relevant to me. ?Try to reduce your problem to the >>> minimal code which exhibits the indicated behaviour. >>> >>> All I can think of, without seeing your offending code, is maybe the >>> IntVar or the Checkbutton is being garbage collected somehow. >>> >>> Regards, >>> >>> John >> >> >> Stripped down fg.py:? http://pastebin.com/m4c32483e >> Stripped down aow.py:? http://pastebin.com/m4ab77b3d >> >> This still exhibits the behavior for me, is anyone else getting it?? Also, >> just realized this laptop is running Ubuntu 8.10, not 9.04, if that makes a >> difference. >> >> -Adam > > Oddly enough, this works:? http://pastebin.com/m5c9cbc1b > It is not really odd, further explanation was given in the previous email. Notice how you create a single interpreter here, and all the widgets and variables are bound to the same Tcl interpreter. > I suppose I could just change all my code to that... > > -Adam -- -- Guilherme H. Polo Goncalves From akadzban at iit.edu Thu Jun 11 06:41:00 2009 From: akadzban at iit.edu (Adam Kadzban) Date: Wed, 10 Jun 2009 23:41:00 -0500 Subject: [Tkinter-discuss] IntVar() not being attached to Checkbutton In-Reply-To: References: <823ecc3a0906101319xe16c910h476f4f198ea90f8d@mail.gmail.com> <4A302EF9.1080702@velseis.com.au> <823ecc3a0906101542i4e91b3er38838089df1df47b@mail.gmail.com> <823ecc3a0906101551k258a616fx114120d839f8bfaa@mail.gmail.com> Message-ID: <823ecc3a0906102141v18603fe0k44ca98b21cfefce2@mail.gmail.com> On Wed, Jun 10, 2009 at 7:16 PM, Guilherme Polo wrote: > On Wed, Jun 10, 2009 at 7:51 PM, Adam Kadzban wrote: > > On Wed, Jun 10, 2009 at 5:42 PM, Adam Kadzban wrote: > >> > >> > >> On Wed, Jun 10, 2009 at 5:08 PM, John McMonagle > >> wrote: > >>> > >>> Adam Kadzban wrote: > >>> > >>> > I have the main part of the GUI (which has Checkbuttons that behave > >>> > normally), with a menu option to create another window for some > >>> > "advanced options". The code for this window is in its own class, > >>> > which > >>> > takes a list of options as parameters and then has some check boxes > and > >>> > entry boxes so you can change the option list. Here's the relevant > >>> > code: > >>> > > >>> > >>> It's not all that relevant to me. Try to reduce your problem to the > >>> minimal code which exhibits the indicated behaviour. > >>> > >>> All I can think of, without seeing your offending code, is maybe the > >>> IntVar or the Checkbutton is being garbage collected somehow. > >>> > >>> Regards, > >>> > >>> John > >> > >> > >> Stripped down fg.py: http://pastebin.com/m4c32483e > >> Stripped down aow.py: http://pastebin.com/m4ab77b3d > >> > >> This still exhibits the behavior for me, is anyone else getting it? > Also, > >> just realized this laptop is running Ubuntu 8.10, not 9.04, if that > makes a > >> difference. > >> > >> -Adam > > > > Oddly enough, this works: http://pastebin.com/m5c9cbc1b > > > > It is not really odd, further explanation was given in the previous > email. Notice how you create a single interpreter here, and all the > widgets and variables are bound to the same Tcl interpreter. > > > I suppose I could just change all my code to that... > > > > -Adam > > -- > -- Guilherme H. Polo Goncalves > Ah, that makes sense. I was thinking aow would have to create a new Tk() instance since it wasn't the same file. But it makes sense that since it's still tied back to the original Tk() instance, it would have to be a Toplevel() instead. Thanks Guilherme! -Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: From kalman_g at msn.com Fri Jun 12 19:34:17 2009 From: kalman_g at msn.com (GKalman) Date: Fri, 12 Jun 2009 10:34:17 -0700 (PDT) Subject: [Tkinter-discuss] locking window size? Message-ID: <24003215.post@talk.nabble.com> How to "lock" top window size with 2 different Frames on it ? I would like to "freeze" the size of the top window, so it can't be changed with the mouse for example: #============================================== from Tkinter import * root=Tk() root.geometry("300x100+10+10") f1=Frame(root,bg="red", width=100,height=100) f1.pack(side=LEFT, expand=0) f2=Frame(root,bg="blue",width=200, height=100) f2.pack(side=LEFT, expand=0) root.mainloop() -- View this message in context: http://www.nabble.com/locking-window-size--tp24003215p24003215.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From bob at passcal.nmt.edu Fri Jun 12 19:42:15 2009 From: bob at passcal.nmt.edu (Bob Greschke) Date: Fri, 12 Jun 2009 11:42:15 -0600 Subject: [Tkinter-discuss] locking window size? In-Reply-To: <24003215.post@talk.nabble.com> References: <24003215.post@talk.nabble.com> Message-ID: <0F021AD0-932F-486C-AF3C-A0D0B944DB81@passcal.nmt.edu> root.resizable(0, 0) or, technically, root.resizable(False, False) (width allowed to be resized?, height allowed to be resized?) after your geometry statement. Just be careful, in general, about controlling the size of things too much what with differing font sizes and stuff on different systems. On Jun 12, 2009, at 11:34, GKalman wrote: > > How to "lock" top window size with 2 different Frames on it ? > I would like to "freeze" the size of the top window, so it can't be > changed > with the mouse > > for example: > #============================================== > from Tkinter import * > > root=Tk() > root.geometry("300x100+10+10") > > f1=Frame(root,bg="red", width=100,height=100) > f1.pack(side=LEFT, expand=0) > > f2=Frame(root,bg="blue",width=200, height=100) > f2.pack(side=LEFT, expand=0) > > root.mainloop() > > -- > View this message in context: http://www.nabble.com/locking-window-size--tp24003215p24003215.html > Sent from the Python - tkinter-discuss mailing list archive at > Nabble.com. > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > From Cameron at phaseit.net Mon Jun 15 01:21:38 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Sun, 14 Jun 2009 23:21:38 +0000 Subject: [Tkinter-discuss] locking window size? In-Reply-To: <24003215.post@talk.nabble.com> References: <24003215.post@talk.nabble.com> Message-ID: <20090614232138.GA5271@lairds.us> On Fri, Jun 12, 2009 at 10:34:17AM -0700, GKalman wrote: . . . > How to "lock" top window size with 2 different Frames on it ? . . . window['resizable'] = false, false From mightyshortadam at gmail.com Thu Jun 18 22:34:38 2009 From: mightyshortadam at gmail.com (Adam Kadzban) Date: Thu, 18 Jun 2009 15:34:38 -0500 Subject: [Tkinter-discuss] Forcing a window to update with while loop running Message-ID: <823ecc3a0906181334p3f1262a4lc2b8dfb65f0542b7@mail.gmail.com> Hi again, let me start off by saying that my code does what I want it to, it's just done in a terribly hackish way, and I'm wondering if there's a better way to do it. I've got a Tkinter window, and when you click a button (the 'run' button), it opens a new window. When the new window opens, it starts running events in a while loop, and there's a 'stop' button on the window. The stop button just turns the 'while' condition variable to 0, so the loop ends. Here's a quick sketch of how I got it to work: ... loop = 1 ... (create a button that sets loop to 0) ... top.update() ... while loop: top.update() ...do stuff... top.update() This works, but I feel like there's got to be a better way to be doing this. I can get rid of the first top.update(), and one of the updates in the loop, but this configuration seems to be the most responsive. And using update_idletasks() doesn't seem to work, at all. Anyone have an idea? -Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: From Cameron at phaseit.net Thu Jun 18 22:47:41 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Thu, 18 Jun 2009 20:47:41 +0000 Subject: [Tkinter-discuss] Forcing a window to update with while loop running In-Reply-To: <823ecc3a0906181334p3f1262a4lc2b8dfb65f0542b7@mail.gmail.com> References: <823ecc3a0906181334p3f1262a4lc2b8dfb65f0542b7@mail.gmail.com> Message-ID: <20090618204741.GA28086@lairds.us> On Thu, Jun 18, 2009 at 03:34:38PM -0500, Adam Kadzban wrote: . . . > Hi again, let me start off by saying that my code does what I want it to, > it's just done in a terribly hackish way, and I'm wondering if there's a > better way to do it. > . . . > ... > loop = 1 > ... > (create a button that sets loop to 0) > ... > top.update() > ... > while loop: > top.update() > ...do stuff... > top.update() > > This works, but I feel like there's got to be a better way to be doing > this. I can get rid of the first top.update(), and one of the updates in > the loop, but this configuration seems to be the most responsive. And using > update_idletasks() doesn't seem to work, at all. > > Anyone have an idea? . . . A. A lot of people through the years have used update(). If you have something already working as you want ... well, there's *considerable* value in that. B. The idiomatic way to do such things in Tkinter is with after() . C. Many programmers also use Python threads to achieve the effect you describe. I don't have an example at hand just now. From mightyshortadam at gmail.com Thu Jun 18 22:58:36 2009 From: mightyshortadam at gmail.com (Adam Kadzban) Date: Thu, 18 Jun 2009 15:58:36 -0500 Subject: [Tkinter-discuss] Forcing a window to update with while loop running In-Reply-To: <20090618204741.GA28086@lairds.us> References: <823ecc3a0906181334p3f1262a4lc2b8dfb65f0542b7@mail.gmail.com> <20090618204741.GA28086@lairds.us> Message-ID: <823ecc3a0906181358s64988176ne17d6f2df007af30@mail.gmail.com> Thanks Cameron. I realize actually having something that works is good, however the "...do stuff..." in my code is controlling an xray beam taking pictures on a CCD, so I want it to be as streamlined as possible. I'll dig through that wiki article though, and maybe take a look at threads. Thanks again, Adam On Thu, Jun 18, 2009 at 3:47 PM, Cameron Laird wrote: > On Thu, Jun 18, 2009 at 03:34:38PM -0500, Adam Kadzban wrote: > . > . > . > > Hi again, let me start off by saying that my code does what I want it to, > > it's just done in a terribly hackish way, and I'm wondering if there's a > > better way to do it. > > > . > . > . > > ... > > loop = 1 > > ... > > (create a button that sets loop to 0) > > ... > > top.update() > > ... > > while loop: > > top.update() > > ...do stuff... > > top.update() > > > > This works, but I feel like there's got to be a better way to be doing > > this. I can get rid of the first top.update(), and one of the updates > in > > the loop, but this configuration seems to be the most responsive. And > using > > update_idletasks() doesn't seem to work, at all. > > > > Anyone have an idea? > . > . > . > A. A lot of people through the years have used update(). > If you have something already working as you want ... > well, there's *considerable* value in that. > B. The idiomatic way to do such things in Tkinter is with > after() . > C. Many programmers also use Python threads to achieve > the effect you describe. I don't have an example at > hand just now. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timj at tolisgroup.com Thu Jun 18 23:15:45 2009 From: timj at tolisgroup.com (Tim Jones) Date: Thu, 18 Jun 2009 14:15:45 -0700 Subject: [Tkinter-discuss] Forcing a window to update with while loop running In-Reply-To: <823ecc3a0906181334p3f1262a4lc2b8dfb65f0542b7@mail.gmail.com> References: <823ecc3a0906181334p3f1262a4lc2b8dfb65f0542b7@mail.gmail.com> Message-ID: <140C07AC-030F-45B0-AFD5-D45BBECE091A@tolisgroup.com> On Jun 18, 2009, at 1:34 PM, Adam Kadzban wrote: > ... > loop = 1 > ... > (create a button that sets loop to 0) > ... top.update() <<--- Remove > ... > while loop: top.update() <<--- Remove > ...do stuff... > top.update() The result here is that the UI will update on each iteration of the loop. I believe that you'll find the two removed calls are really not necessary since the result in the loop is to call update() at the bottom of the loop and then immediately again at the entry to the loop. Or, place your actual loop code in a thread which allows the top event loop to stay responsive. HTH, Tim From Cameron at phaseit.net Thu Jun 18 23:50:33 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Thu, 18 Jun 2009 21:50:33 +0000 Subject: [Tkinter-discuss] Forcing a window to update with while loop running In-Reply-To: <823ecc3a0906181358s64988176ne17d6f2df007af30@mail.gmail.com> References: <823ecc3a0906181334p3f1262a4lc2b8dfb65f0542b7@mail.gmail.com> <20090618204741.GA28086@lairds.us> <823ecc3a0906181358s64988176ne17d6f2df007af30@mail.gmail.com> Message-ID: <20090618215033.GA7756@lairds.us> On Thu, Jun 18, 2009 at 03:58:36PM -0500, Adam Kadzban wrote: . . . > Thanks Cameron. I realize actually having something that works is good, > however the "...do stuff..." in my code is controlling an xray beam taking > pictures on a CCD, so I want it to be as streamlined as possible. I'll dig > through that wiki article though, and maybe take a look at threads. . . . I repeat: others have traveled the same path (well, maybe not with X-rays). is typical. My personal favorite is to use after(); here's an example you'll probably prefer to the Wiki page I earlier sent: . We need more of our own Wiki pages; is the closest we currently have to your situation. From kalman_g at msn.com Mon Jun 22 13:51:20 2009 From: kalman_g at msn.com (GKalman) Date: Mon, 22 Jun 2009 04:51:20 -0700 (PDT) Subject: [Tkinter-discuss] Tkinter mouse-event w/o class and/or global? Message-ID: <24145910.post@talk.nabble.com> As an example: I want to click on a Canvas and with that change its background color. The "usual" way is to declare a class (i.e a namespace). An other way is declare c=Canvas(...) as global. Question: Is it possible to do this without a class (OOP) or global variables? -- View this message in context: http://www.nabble.com/Tkinter-mouse-event-w-o-class-and-or-global--tp24145910p24145910.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From Cameron at phaseit.net Mon Jun 22 14:20:38 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Mon, 22 Jun 2009 12:20:38 +0000 Subject: [Tkinter-discuss] Tkinter mouse-event w/o class and/or global? In-Reply-To: <24145910.post@talk.nabble.com> References: <24145910.post@talk.nabble.com> Message-ID: <20090622122038.GA12274@lairds.us> On Mon, Jun 22, 2009 at 04:51:20AM -0700, GKalman wrote: . . . > As an example: > > I want to click on a Canvas and with that change its background color. > > The "usual" way is to declare a class (i.e a namespace). > > An other way is declare c=Canvas(...) as global. > > Question: > > Is it possible to do this without a class (OOP) or global variables? . . . Yes. I *think* the following exemplifies what you seek: # Launch this application. Notice the red canvas. Click on it. import Tkinter def toggle_color(event): c = event.widget if c.cget("bg") == "red": new_color = "green" else: new_color = "red" c.configure(bg = new_color) root = Tkinter.Tk() my_canvas = Tkinter.Canvas(root, bg = "red") my_canvas.bind("", toggle_color) my_canvas.pack() root.mainloop() From kalman_g at msn.com Mon Jun 22 15:07:51 2009 From: kalman_g at msn.com (GKalman) Date: Mon, 22 Jun 2009 06:07:51 -0700 (PDT) Subject: [Tkinter-discuss] Tkinter mouse-event w/o class and/or global? In-Reply-To: <24145910.post@talk.nabble.com> References: <24145910.post@talk.nabble.com> Message-ID: <24146898.post@talk.nabble.com> Thank you so much for your PROMPT reply. Now I do understand what "event.widget" means. Please consider this issue [RESOLVED] GKalman wrote: > > > As an example: > > I want to click on a Canvas and with that change its background color. > > The "usual" way is to declare a class (i.e a namespace). > > An other way is declare c=Canvas(...) as global. > > Question: > > Is it possible to do this without a class (OOP) or global variables? > -- View this message in context: http://www.nabble.com/Tkinter-mouse-event-w-o-class-and-or-global--tp24145910p24146898.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From kalman_g at msn.com Mon Jun 22 21:00:15 2009 From: kalman_g at msn.com (GKalman) Date: Mon, 22 Jun 2009 12:00:15 -0700 (PDT) Subject: [Tkinter-discuss] Communicating between objects w/o class and/or global? Message-ID: <24153330.post@talk.nabble.com> Recently I posted, on this Forum, a msg titled: "Tkinter mouse-event w/o class and/or global?" It was successfuly [RESOLVED] . ow I have related Question: I have two (c1 & c2) Canvas instances. If I mouse-click on one of the canvases (or more likely on a drawn item on the canvas, e.g. on a rectangle), I would like to change the background color of the other canvas. Can I do it without classes (OOP) and/or global-variables? -- View this message in context: http://www.nabble.com/Communicating-between-objects-w-o-class-and-or-global--tp24153330p24153330.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From Cameron at phaseit.net Tue Jun 23 01:32:56 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Mon, 22 Jun 2009 23:32:56 +0000 Subject: [Tkinter-discuss] Communicating between objects w/o class and/or global? In-Reply-To: <24153330.post@talk.nabble.com> References: <24153330.post@talk.nabble.com> Message-ID: <20090622233256.GA23678@lairds.us> On Mon, Jun 22, 2009 at 12:00:15PM -0700, GKalman wrote: . . . > Recently I posted, on this Forum, a msg titled: "Tkinter mouse-event w/o > class and/or global?" It was successfuly [RESOLVED] . > > ow I have related Question: > > I have two (c1 & c2) Canvas instances. If I mouse-click on one of the > canvases (or more likely on a drawn item on the canvas, e.g. on a > rectangle), I would like to change the background color of the other canvas. > > Can I do it without classes (OOP) and/or global-variables? . . . Like the following? import Tkinter def toggle_color(c): if c.cget("bg") == "red": new_color = "green" else: new_color = "red" c.configure(bg = new_color) root = Tkinter.Tk() c1 = Tkinter.Canvas(root, bg = "red") c2 = Tkinter.Canvas(root, bg = "red") c1.bind("", lambda event: toggle_color(c2)) c2.bind("", lambda event: toggle_color(c1)) c1.pack() c2.pack() root.mainloop() From jmcmonagle at velseis.com.au Tue Jun 23 01:34:43 2009 From: jmcmonagle at velseis.com.au (John McMonagle) Date: Tue, 23 Jun 2009 09:34:43 +1000 Subject: [Tkinter-discuss] Communicating between objects w/o class and/or global? In-Reply-To: <24153330.post@talk.nabble.com> References: <24153330.post@talk.nabble.com> Message-ID: <20090622232835.M81144@velseis.com.au> > Recently I posted, on this Forum, a msg titled: "Tkinter mouse- > event w/o class and/or global?" It was successfuly [RESOLVED] . > > ow I have related Question: > > I have two (c1 & c2) Canvas instances. If I mouse-click on one of the > canvases (or more likely on a drawn item on the canvas, e.g. on a > rectangle), I would like to change the background color of the other > canvas. > > Can I do it without classes (OOP) and/or global-variables? > Sure can, you just have to pass the widget id as a parameter to the function. For example: import Tkinter as tk root = tk.Tk() c1 = tk.Canvas(root, bg='green') c2 = tk.Canvas(root, bg='red') c1.pack() c2.pack() def changeColour(event, c): if c.cget('bg') == 'red': c.configure(bg='green') else: c.configure(bg='red') c1.bind('', lambda e, c=c2: changeColour(e, c)) c2.bind('', lambda e, c=c1: changeColour(e, c)) root.mainloop() Regards, John From kalman_g at msn.com Tue Jun 23 02:24:02 2009 From: kalman_g at msn.com (GKalman) Date: Mon, 22 Jun 2009 17:24:02 -0700 (PDT) Subject: [Tkinter-discuss] [correction] Communicating between objects w/o class and/or global? In-Reply-To: <24153330.post@talk.nabble.com> References: <24153330.post@talk.nabble.com> Message-ID: <24157939.post@talk.nabble.com> Thanks to both of you. GKalman wrote: > > Recently I posted, on this Forum, a msg titled: "Tkinter mouse-event w/o > class and/or global?" It was successfuly [RESOLVED] . > > Now I have a related Question: [sorry for the typo] > > I have two (c1 & c2) Canvas instances. If I mouse-click on one of the > canvases (or more likely on a drawn item on the canvas, e.g. on a > rectangle), I would like to change the background color of the other > canvas. > > Can I do it without classes (OOP) and/or global-variables? > > -- View this message in context: http://www.nabble.com/-correction--Communicating-between-objects-w-o-class-and-or-global--tp24153330p24157939.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From Cameron at phaseit.net Tue Jun 23 02:52:45 2009 From: Cameron at phaseit.net (Cameron Laird) Date: Tue, 23 Jun 2009 00:52:45 +0000 Subject: [Tkinter-discuss] [correction] Communicating between objects w/o class and/or global? In-Reply-To: <24157939.post@talk.nabble.com> References: <24153330.post@talk.nabble.com> <24157939.post@talk.nabble.com> Message-ID: <20090623005245.GA21753@lairds.us> On Mon, Jun 22, 2009 at 05:24:02PM -0700, GKalman wrote: . . . > Thanks to both of you. . . . Confirmation that these answers indeed serve you--which you have faithfully supplied--is a good way to give thanks. Another is to memorialize insights in the Wiki, for example, at . From mightyshortadam at gmail.com Tue Jun 23 19:20:10 2009 From: mightyshortadam at gmail.com (Adam Kadzban) Date: Tue, 23 Jun 2009 12:20:10 -0500 Subject: [Tkinter-discuss] Forcing a window to update with while loop running In-Reply-To: <20090618215033.GA7756@lairds.us> References: <823ecc3a0906181334p3f1262a4lc2b8dfb65f0542b7@mail.gmail.com> <20090618204741.GA28086@lairds.us> <823ecc3a0906181358s64988176ne17d6f2df007af30@mail.gmail.com> <20090618215033.GA7756@lairds.us> Message-ID: <823ecc3a0906231020u4f910c71q7da4617a22657fea@mail.gmail.com> Seems to be working - I have after() running to update the window's status box, and check for the "stop" button press, as well as a forced update at the end of the while loop to make sure it doesn't miss a button press . Thanks again, Adam On Thu, Jun 18, 2009 at 4:50 PM, Cameron Laird wrote: > On Thu, Jun 18, 2009 at 03:58:36PM -0500, Adam Kadzban wrote: > . > . > . > > Thanks Cameron. I realize actually having something that works is good, > > however the "...do stuff..." in my code is controlling an xray beam > taking > > pictures on a CCD, so I want it to be as streamlined as possible. I'll > dig > > through that wiki article though, and maybe take a look at threads. > . > . > . > I repeat: others have traveled the same path (well, maybe not > with X-rays). http://bytes.com/groups/python/623383-use-threads-tkinter-event-loop > > is typical. > > My personal favorite is to use after(); here's an example you'll > probably prefer to the Wiki page I earlier sent: > http://stackoverflow.com/questions/459083/how-do-you-run-your-own-code-alongside-tkinters-event-loop>. > > We need more of our own Wiki pages; http://tkinter.unpy.net/wiki/ProgressMeter?highlight=(after)> > is the closest we currently have to your situation. > _______________________________________________ > 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 bob at passcal.nmt.edu Mon Jun 29 23:58:24 2009 From: bob at passcal.nmt.edu (Bob Greschke) Date: Mon, 29 Jun 2009 15:58:24 -0600 Subject: [Tkinter-discuss] Canvas postscript fun Message-ID: <756EC1E1-C77A-4502-BB29-538F95E00187@passcal.nmt.edu> After about 5 years of on and off goofing around I finally, yesterday, got the Canvas postscript command to produce a postscript file with ALL of the contents of a canvas in it, instead of just what was visible at the time. This did it: L, T, R, B = LCan.bbox(ALL) Ps = LCan.postscript(height = B, width = R, pageheight = B, \ pagewidth = R, x = 0, y = 0) The write Ps to a file. The problem is the Canvas in the program I have is 8000 pixels wide by 1000 pixels tall (or bigger or smaller). Anything that wants to print the file wants to keep everything squished on to one page. Is there a way through the command to get downstream programs to "span" the image across more than one page (I'd maybe have to calculate something on-the-fly, but that would be OK)? A screen shot of what I'm trying to print is here. It's in the out.pdf Preview program (OS X) window: www.passcal.nmt.edu/~bob/unlinked/images/big.tiff Thanks! Bob