From jrcagle at juno.com Wed Oct 1 05:15:23 2008 From: jrcagle at juno.com (Jeff Cagle) Date: Tue, 30 Sep 2008 23:15:23 -0400 Subject: [Tkinter-discuss] validation woes Message-ID: <48E2EB4B.9040905@juno.com> I want an Entry widget to accept a single digit only. Here's the attempt: --- import Tkinter as Tk class MyEntry(Tk.Entry): def __init__(self, parent, **kwargs): kwargs['validate']='key' # could also be 'all' -- has the same result kwargs['vcmd']=self.validate Tk.Entry.__init__(self, parent, **kwargs) def validate(self): print self.get() # diagnostic only if self.get() in [''] + list("123456789"): return True else: self.bell() return False if __name__=="__main__": main = Tk.Tk() main.e = MyEntry(main) main.e.grid() main.mainloop() --- I'd like to think this is straightforward, but No. I type in MyEntry: 1 printed value: (empty string) contents of MyEntry: 1 I type in MyEntry: 11 printed value: 1 contents of MyEntry: 11 I type in MyEntry: 111 (bell rings) printed value: 11 contents of MyEntry: 11 I type in MyEntry: a printed value: (empty string) contents of MyEntry: a I type in MyEntry: a1 (bell rings) printed value: a contents of MyEntry: a Near as I can tell, validate() is called after a key is pressed and displayed in the Entry widget, but *before* the pressed key has been added to MyEntry's contents. Hence, validate() has no way of knowing what the new keypress is -- it can only validate the past entry. Once it does so, the new key is added to MyEntry's contents. How can validate() discover the new keypress in order to validate it prior to addition to the Entry widget? Yikes! Thanks in advance, Jeff Cagle From makarovalexey at gmail.com Wed Oct 1 17:22:19 2008 From: makarovalexey at gmail.com (=?UTF-8?B?0JDQu9C10LrRgdC10Lkg0JzQsNC60LDRgNC+0LI=?=) Date: Wed, 1 Oct 2008 19:22:19 +0400 Subject: [Tkinter-discuss] Fwd: Python + Tk/Tcl building In-Reply-To: <49e9c720810010820t2e6d2c9ai421910e9d30c7b58@mail.gmail.com> References: <49e9c720810010820t2e6d2c9ai421910e9d30c7b58@mail.gmail.com> Message-ID: <49e9c720810010822o7a4ce372xc6232844de91da35@mail.gmail.com> Hello! I want to build python with Tk/Tcl by mysel. When writing coomand ?import Tkinter? tehere is an error >>> import Tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/Py/lib/python2.5/lib-tk/Tkinter.py", line 38, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter >>> I don understand, how should I bild python for it work correctly. Is there some options in ./configure command for this? -- Best regards, Makarov Alexey From timj at tolisgroup.com Wed Oct 1 17:53:33 2008 From: timj at tolisgroup.com (Tim Jones) Date: Wed, 1 Oct 2008 08:53:33 -0700 Subject: [Tkinter-discuss] Fwd: Python + Tk/Tcl building In-Reply-To: <49e9c720810010822o7a4ce372xc6232844de91da35@mail.gmail.com> References: <49e9c720810010820t2e6d2c9ai421910e9d30c7b58@mail.gmail.com> <49e9c720810010822o7a4ce372xc6232844de91da35@mail.gmail.com> Message-ID: <9ACE5A1D-E0C5-4E66-8C92-F150D6EA91FA@tolisgroup.com> On Oct 1, 2008, at 8:22 AM, ??????? ??????? wrote: > Hello! > > I want to build python with Tk/Tcl by mysel. When writing coomand > ?import Tkinter? tehere is an error > >> > import Tkinter > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/Py/lib/python2.5/lib-tk/Tkinter.py", line 38, in > > import _tkinter # If this fails your Python may not be configured > for Tk > ImportError: No module named _tkinter >> > > > I don understand, how should I bild python for it work correctly. Is > there some options in ./configure command for this? Hello Alexey, In the case of TKinter, you need to make sure that the TCL/TK developer sources are built and installed properly as the first step. Once they are installed, you will need to edit your Python Modules/ Setup file and remove the comment symbols in front of the TKInter entries that apply to what you are building. You can find this by searching for _tkinter once you've opened the Setup file in your editor. HTH, Tim From makarovalexey at gmail.com Wed Oct 1 17:20:35 2008 From: makarovalexey at gmail.com (=?UTF-8?B?0JDQu9C10LrRgdC10Lkg0JzQsNC60LDRgNC+0LI=?=) Date: Wed, 1 Oct 2008 19:20:35 +0400 Subject: [Tkinter-discuss] Python + Tk/Tcl building Message-ID: <49e9c720810010820t2e6d2c9ai421910e9d30c7b58@mail.gmail.com> Hello! I want to build python with Tk/Tcl by mysel. When writing coomand ?import Tkinter? tehere is an error >>> import Tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/Py/lib/python2.5/lib-tk/Tkinter.py", line 38, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter >>> I don understand, how should i buld python for it work correctly. Is there some options in ./configure command for this? -- Best regards, Makarov Alexey From ggpolo at gmail.com Mon Oct 6 22:22:28 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Mon, 6 Oct 2008 17:22:28 -0300 Subject: [Tkinter-discuss] validation woes In-Reply-To: <48E2EB4B.9040905@juno.com> References: <48E2EB4B.9040905@juno.com> Message-ID: On Wed, Oct 1, 2008 at 12:15 AM, Jeff Cagle wrote: > I want an Entry widget to accept a single digit only. Here's the attempt: > > --- > import Tkinter as Tk > > class MyEntry(Tk.Entry): > > def __init__(self, parent, **kwargs): > kwargs['validate']='key' # could also be 'all' -- has the same > result > kwargs['vcmd']=self.validate > Tk.Entry.__init__(self, parent, **kwargs) > > def validate(self): > print self.get() # diagnostic only > if self.get() in [''] + list("123456789"): > return True > else: > self.bell() > return False > > if __name__=="__main__": > main = Tk.Tk() > main.e = MyEntry(main) > main.e.grid() > main.mainloop() > > --- > > I'd like to think this is straightforward, but No. > > I type in MyEntry: 1 > printed value: (empty string) > contents of MyEntry: 1 > > I type in MyEntry: 11 > printed value: 1 > contents of MyEntry: 11 > > I type in MyEntry: 111 (bell rings) > printed value: 11 > contents of MyEntry: 11 > > I type in MyEntry: a > printed value: (empty string) > contents of MyEntry: a > > I type in MyEntry: a1 (bell rings) > printed value: a > contents of MyEntry: a > > Near as I can tell, validate() is called after a key is pressed and > displayed in the Entry widget, but *before* the pressed key has been added > to MyEntry's contents. Hence, validate() has no way of knowing what the new > keypress is -- it can only validate the past entry. validate does have a way to know that. > Once it does so, the > new key is added to MyEntry's contents. > > How can validate() discover the new keypress in order to validate it prior > to addition to the Entry widget? Yikes! > Tkinter is a bit unfortunate in this situation, but Tk does provide what you are after so you can use it in Tkinter. You will have to change your: kwargs['vcmd']=self.validate to (after you call the __init__ method from Tk.Entry): kwargs['vcmd'] = (self.register(self.validate), '%P') # '%P' pass the possible new value for the entry, if it is validated or to: kwargs['vcmd'] = (self.register(self.validate), '%S') # '%S' will pass the text being inserted/deleted probably, based on what you described. There are some other substitutions that could be applied and combined if you are interested, they are all described in the entry widget manual in the tcl/tk site. Also, I believe if you use a textvariable with this entry then it will contain the new text when the validatecommand callback is invoked. > Thanks in advance, > Jeff Cagle > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- -- Guilherme H. Polo Goncalves From fred.mailhot at gmail.com Thu Oct 9 22:16:49 2008 From: fred.mailhot at gmail.com (Fred Mailhot) Date: Thu, 9 Oct 2008 16:16:49 -0400 Subject: [Tkinter-discuss] Unicode on Mac (yet again) In-Reply-To: References: Message-ID: *bump* 2008/8/18 Dave Opstad : > > The first thing that strikes me is an endian issue. You're asking for > Unicode 026E, but Unicode 6E02 might be what you're getting (and it's in the > CJK ideograph range). Is there an endian compiler flag you need to set when > you recompile your python for linking to Tcl/Tk 8.5? Did some tests, it's not and endian thing. Has *anybody* gotten Unicode working on Macs with Tkinter Label or Text widgets? Any help is *much* appreciated... F. From Allen.Taylor at mdacorporation.com Thu Oct 23 22:16:58 2008 From: Allen.Taylor at mdacorporation.com (Allen Taylor) Date: Thu, 23 Oct 2008 16:16:58 -0400 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter Message-ID: <4900A377.FA48.005C.0@mdacorporation.com> I was given the task of upgrading a Python/Tkinter GUI application to the latest versions of Python and Tk. After a while, I realized that the application had not been written in a thread-safe manner. Multiple threads would simply use the Tk object directly. The application apparently ran fine (i.e., didn't crash!) using older versions of Python (2.2) and Tk (8.3), but it started to have serious problems (i.e., crashing) after using the latest versions. The problem is that there isn't enough budget to fix the whole application. So, I invested a bit of time to develop mtTkinter, a thread-safe version of Tkinter. Importing mtTkinter actually modifies the original Tkinter in such a way to make it thread-safe, recognizing and diverting out-of-thread calls to the Tk object creation thread via a queue and an 'after' event. I think it works quite well, requiring basically no changes to the application other than to import mtTkinter instead of (or in addition to) Tkinter. Even packages that use Tkinter (e.g., Pmw) benefit. I would like to contribute this module (single file, about 160 lines) to the Python community, but I don't know how. I'm new to Python and am not initiated in the deep Pythonic developer world. Can someone give me some pointers? Many thanks. Allen B. Taylor MDA 9445 Airport Road Brampton, ON L6S 4J3 905-790-2800 ext. 4350 allen.taylor at mdacorporation.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ron.longo at cox.net Fri Oct 24 03:31:54 2008 From: ron.longo at cox.net (Ron Longo) Date: Thu, 23 Oct 2008 21:31:54 -0400 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: <4900A377.FA48.005C.0@mdacorporation.com> References: <4900A377.FA48.005C.0@mdacorporation.com> Message-ID: Allen, Sounds like you have a great module there which many people could benefit from. I would recommend you post your module to the tkinter wiki (http://tkinter.unpythonic.net/wiki/). You may also consider packaging it up and posting it to the python package index. Thanks, Ron ----- Original Message ----- From: Allen Taylor To: Tkinter-discuss at python.org Sent: Thursday, October 23, 2008 4:16 PM Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter I was given the task of upgrading a Python/Tkinter GUI application to the latest versions of Python and Tk. After a while, I realized that the application had not been written in a thread-safe manner. Multiple threads would simply use the Tk object directly. The application apparently ran fine (i.e., didn't crash!) using older versions of Python (2.2) and Tk (8.3), but it started to have serious problems (i.e., crashing) after using the latest versions. The problem is that there isn't enough budget to fix the whole application. So, I invested a bit of time to develop mtTkinter, a thread-safe version of Tkinter. Importing mtTkinter actually modifies the original Tkinter in such a way to make it thread-safe, recognizing and diverting out-of-thread calls to the Tk object creation thread via a queue and an 'after' event. I think it works quite well, requiring basically no changes to the application other than to import mtTkinter instead of (or in addition to) Tkinter. Even packages that use Tkinter (e.g., Pmw) benefit. I would like to contribute this module (single file, about 160 lines) to the Python community, but I don't know how. I'm new to Python and am not initiated in the deep Pythonic developer world. Can someone give me some pointers? Many thanks. Allen B. Taylor MDA 9445 Airport Road Brampton, ON L6S 4J3 905-790-2800 ext. 4350 allen.taylor at mdacorporation.com ------------------------------------------------------------------------------ _______________________________________________ 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 callen at gemini.edu Fri Oct 24 04:05:00 2008 From: callen at gemini.edu (C. Allen) Date: Thu, 23 Oct 2008 16:05:00 -1000 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: <4900A377.FA48.005C.0@mdacorporation.com> References: <4900A377.FA48.005C.0@mdacorporation.com> Message-ID: <1224813900.11748.17.camel@phact.hi.gemini.edu> cool work, that would be a great thing to have. On Thu, 2008-10-23 at 16:16 -0400, Allen Taylor wrote: > I was given the task of upgrading a Python/Tkinter GUI application to > the latest versions of Python and Tk. After a while, I realized that > the application had not been written in a thread-safe manner. Multiple > threads would simply use the Tk object directly. The application > apparently ran fine (i.e., didn't crash!) using older versions of > Python (2.2) and Tk (8.3), but it started to have serious problems > (i.e., crashing) after using the latest versions. > > The problem is that there isn't enough budget to fix the whole > application. So, I invested a bit of time to develop mtTkinter, a > thread-safe version of Tkinter. Importing mtTkinter actually modifies > the original Tkinter in such a way to make it thread-safe, recognizing > and diverting out-of-thread calls to the Tk object creation thread via > a queue and an 'after' event. I think it works quite well, requiring > basically no changes to the application other than to import mtTkinter > instead of (or in addition to) Tkinter. Even packages that use Tkinter > (e.g., Pmw) benefit. > > I would like to contribute this module (single file, about 160 lines) > to the Python community, but I don't know how. I'm new to Python and > am not initiated in the deep Pythonic developer world. Can someone > give me some pointers? Many thanks. > > > Allen B. Taylor > MDA > 9445 Airport Road > Brampton, ON L6S 4J3 > 905-790-2800 ext. 4350 > allen.taylor at mdacorporation.com > > _______________________________________________ > 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 Allen.Taylor at mdacorporation.com Fri Oct 24 19:56:50 2008 From: Allen.Taylor at mdacorporation.com (Allen Taylor) Date: Fri, 24 Oct 2008 13:56:50 -0400 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: References: <4900A377.FA48.005C.0@mdacorporation.com> Message-ID: <4901D420.FA48.005C.0@mdacorporation.com> All, Please find mtTkinter, a thread-safe version of Tkinter, at http://tkinter.unpythonic.net/wiki/mtTkinter. If you find it useful, or if you find bugs, please let me know. Enjoy! Allen >>> "Ron Longo" 2008-10-23 21:31 >>> Allen, Sounds like you have a great module there which many people could benefit from. I would recommend you post your module to the tkinter wiki (http://tkinter.unpythonic.net/wiki/). You may also consider packaging it up and posting it to the python package index. Thanks, Ron ----- Original Message ----- From: Allen Taylor ( mailto:Allen.Taylor at mdacorporation.com ) To: Tkinter-discuss at python.org Sent: Thursday, October 23, 2008 4:16 PM Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter I was given the task of upgrading a Python/Tkinter GUI application to the latest versions of Python and Tk. After a while, I realized that the application had not been written in a thread-safe manner. Multiple threads would simply use the Tk object directly. The application apparently ran fine (i.e., didn't crash!) using older versions of Python (2.2) and Tk (8.3), but it started to have serious problems (i.e., crashing) after using the latest versions. The problem is that there isn't enough budget to fix the whole application. So, I invested a bit of time to develop mtTkinter, a thread-safe version of Tkinter. Importing mtTkinter actually modifies the original Tkinter in such a way to make it thread-safe, recognizing and diverting out-of-thread calls to the Tk object creation thread via a queue and an 'after' event. I think it works quite well, requiring basically no changes to the application other than to import mtTkinter instead of (or in addition to) Tkinter. Even packages that use Tkinter (e.g., Pmw) benefit. I would like to contribute this module (single file, about 160 lines) to the Python community, but I don't know how. I'm new to Python and am not initiated in the deep Pythonic developer world. Can someone give me some pointers? Many thanks. Allen B. Taylor MDA 9445 Airport Road Brampton, ON L6S 4J3 905-790-2800 ext. 4350 allen.taylor at mdacorporation.com _______________________________________________ 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 ggpolo at gmail.com Fri Oct 24 21:00:16 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Fri, 24 Oct 2008 17:00:16 -0200 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: <49009CF6.FA48.005C.0@mdacorporation.com> References: <49009CF6.FA48.005C.0@mdacorporation.com> Message-ID: On Thu, Oct 23, 2008 at 5:49 PM, Allen Taylor wrote: > I was given the task of upgrading a Python/Tkinter GUI application to the > latest versions of Python and Tk. After a while, I realized that the > application had not been written in a thread-safe manner. Multiple threads > would simply use the Tk object directly. The application apparently ran fine > (i.e., didn't crash!) using older versions of Python (2.2) and Tk (8.3), but > it started to have serious problems (i.e., crashing) after using the latest > versions. Did you compile these new tcl/tk versions with --enable-threads ? That is where the problem lies in _tkinter currently. In a tk.call it checks if python was compiled with threads, but if tcl wasn't compiled with threads support too, _tkinter acts like single threaded and then you get these crashes (this happens in other places there too). > > The problem is that there isn't enough budget to fix the whole application. > So, I invested a bit of time to develop mtTkinter, a thread-safe version of > Tkinter. Importing mtTkinter actually modifies the original Tkinter in such > a way to make it thread-safe, recognizing and diverting out-of-thread calls > to the Tk object creation thread via a queue and an 'after' event. I think > it works quite well, requiring basically no changes to the application other > than to import mtTkinter instead of (or in addition to) Tkinter. Even > packages that use Tkinter (e.g., Pmw) benefit. > > I would like to contribute this module (single file, about 160 lines) to the > Python community, but I don't know how. I'm new to Python and am not > initiated in the deep Pythonic developer world. Can someone give me some > pointers? Many thanks. > I have read your other email where you posted the code for this module but let me comment on it here too. It is nice that it fixes the problem mentioned above ;) And I believe _tkinter deserves a fix in this respect, I don't think it was intended to not work correctly when python has thread support and tcl/tk doesn't. > Allen B. Taylor > MDA > 9445 Airport Road > Brampton, ON L6S 4J3 > 905-790-2800 ext. 4350 > allen.taylor at mdacorporation.com > -- > http://mail.python.org/mailman/listinfo/python-list > > -- -- Guilherme H. Polo Goncalves From Allen.Taylor at mdacorporation.com Fri Oct 24 21:31:44 2008 From: Allen.Taylor at mdacorporation.com (Allen Taylor) Date: Fri, 24 Oct 2008 15:31:44 -0400 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: References: <49009CF6.FA48.005C.0@mdacorporation.com> Message-ID: <4901EA5D.FA48.005C.0@mdacorporation.com> Hi Guilherme, The versions of Python and Tk used are the default packages installed on Linux (Ubuntu 6.06 LTS). I don't know whether the default install is compiled with --enable-threads or not. So, mtTkinter seems to be handy if you want to use the default installed packages? Allen >>> "Guilherme Polo" 2008-10-24 15:00 >>> On Thu, Oct 23, 2008 at 5:49 PM, Allen Taylor wrote: > I was given the task of upgrading a Python/Tkinter GUI application to the > latest versions of Python and Tk. After a while, I realized that the > application had not been written in a thread-safe manner. Multiple threads > would simply use the Tk object directly. The application apparently ran fine > (i.e., didn't crash!) using older versions of Python (2.2) and Tk (8.3), but > it started to have serious problems (i.e., crashing) after using the latest > versions. Did you compile these new tcl/tk versions with --enable-threads ? That is where the problem lies in _tkinter currently. In a tk.call it checks if python was compiled with threads, but if tcl wasn't compiled with threads support too, _tkinter acts like single threaded and then you get these crashes (this happens in other places there too). > > The problem is that there isn't enough budget to fix the whole application. > So, I invested a bit of time to develop mtTkinter, a thread-safe version of > Tkinter. Importing mtTkinter actually modifies the original Tkinter in such > a way to make it thread-safe, recognizing and diverting out-of-thread calls > to the Tk object creation thread via a queue and an 'after' event. I think > it works quite well, requiring basically no changes to the application other > than to import mtTkinter instead of (or in addition to) Tkinter. Even > packages that use Tkinter (e.g., Pmw) benefit. > > I would like to contribute this module (single file, about 160 lines) to the > Python community, but I don't know how. I'm new to Python and am not > initiated in the deep Pythonic developer world. Can someone give me some > pointers? Many thanks. > I have read your other email where you posted the code for this module but let me comment on it here too. It is nice that it fixes the problem mentioned above ;) And I believe _tkinter deserves a fix in this respect, I don't think it was intended to not work correctly when python has thread support and tcl/tk doesn't. > Allen B. Taylor > MDA > 9445 Airport Road > Brampton, ON L6S 4J3 > 905-790-2800 ext. 4350 > allen.taylor at mdacorporation.com > -- > http://mail.python.org/mailman/listinfo/python-list > > -- -- Guilherme H. Polo Goncalves -------------- next part -------------- An HTML attachment was scrubbed... URL: From ggpolo at gmail.com Fri Oct 24 21:45:39 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Fri, 24 Oct 2008 17:45:39 -0200 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: <4901EA5D.FA48.005C.0@mdacorporation.com> References: <49009CF6.FA48.005C.0@mdacorporation.com> <4901EA5D.FA48.005C.0@mdacorporation.com> Message-ID: On Fri, Oct 24, 2008 at 5:31 PM, Allen Taylor wrote: > Hi Guilherme, > The versions of Python and Tk used are the default packages installed on > Linux (Ubuntu 6.06 LTS). I don't know whether the default install is > compiled with --enable-threads or not. So, mtTkinter seems to be handy if > you want to use the default installed packages? > Allen > To check for --enable-threads try this: import Tkinter Tkinter.Tk().getvar("tcl_platform(threaded)") You will either get 1, or a TclError. Also, I though you said latest tcl/tk versions but clearly tcl/tk packages in Ubuntu 6.06 are not the latest. But they also won't make a difference if you didn't recompile python with these packages, I'm just telling this because right now Ubuntu includes tcl/tk 8.5 but distributes python-tk compiled against tcl/tk 8.4. Maybe you could include one example where this new module makes a difference ? We could be talking about different things. For instance, this: import Tkinter def test(text_widget): text_widget.config(text='abcdef') def try_it(text_widget): threading.Thread(target=test, args=(text_widget, )).start() lbl = Tkinter.Label() lbl.pack() lbl.after(10, lambda: try_it(lbl)) lbl.mainloop() Would crash if tcl/tk were not compiled with --threads-enabled, but then using your module it will run just fine. -- -- Guilherme H. Polo Goncalves From Allen.Taylor at mdacorporation.com Mon Oct 27 15:59:30 2008 From: Allen.Taylor at mdacorporation.com (Allen Taylor) Date: Mon, 27 Oct 2008 10:59:30 -0400 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter Message-ID: <49059F0E.FA48.005C.0@mdacorporation.com> All, After a very helpful discussion with "Guilherme Polo ", we have come to the following conclusion regarding multithreaded applications and Tkinter. Although Tk is technically thread-safe (if built with --enable-threads), practically speaking it still has problems when used in multithreaded applications. The problem stems from the fact that _tkinter attempts to gain control of the main thread via a polling technique. If it succeeds, all is well. If it fails, however, the application receives an exception with the message "RuntimeError: main thread is not in main loop". There is no way to tell when this might happen, so calling Tk routines from multiple threads seems to be problematic at best. The mtTkinter module I published last week (http://tkinter.unpythonic.net/wiki/mtTkinter) solves this problem by marshaling calls coming from multiple threads through a queue which is read by an 'after' event running periodically in the main loop. This is similar to the technique used in many other platforms (e.g., .NET's InvokeRequired/Invoke mechanism). The technique used in mtTkinter is exception-safe as well, marshaling exceptions through a response queue back to the caller's thread. If a similar technique were employed in _tkinter instead of the polling technique, that would be a preferable solution. In the meantime, mtTkinter will work as a good stop-gap measure. Allen B. Taylor -------------- next part -------------- An HTML attachment was scrubbed... URL: From ggpolo at gmail.com Mon Oct 27 18:10:33 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Mon, 27 Oct 2008 15:10:33 -0200 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: <49059F0E.FA48.005C.0@mdacorporation.com> References: <49059F0E.FA48.005C.0@mdacorporation.com> Message-ID: On Mon, Oct 27, 2008 at 12:59 PM, Allen Taylor wrote: > All, > After a very helpful discussion with "Guilherme Polo ", we > have come to the following conclusion regarding multithreaded applications > and Tkinter. Although Tk is technically thread-safe (if built with > --enable-threads), practically speaking it still has problems when used in > multithreaded applications. Now that I reread it, I see you said "Tk is technically thread-safe (if built with --enable-threads)". It is not true, what happens is that tkinter makes it thread safe by using some mutexes and scheduling actions to go through the thread that created the tcl interpreter, which otherwise would happen elsewhere. But tk isn't thread safe per se (only tcl, since version 8.1). At the same time, if tk is compiled without thread support but python has thread support, then tkinter fails miserably to protect against multiple threads from python from accessing tk. And again, your module does help in this case since all the interaction to tk will occur through main thread, independent of tk having thread support or not. > The problem stems from the fact that _tkinter > attempts to gain control of the main thread via a polling technique. If it > succeeds, all is well. If it fails, however, the application receives an > exception with the message "RuntimeError: main thread is not in main loop". > There is no way to tell when this might happen, so calling Tk routines from > multiple threads seems to be problematic at best. > The mtTkinter module I published last week > (http://tkinter.unpythonic.net/wiki/mtTkinter) solves this problem by > marshaling calls coming from multiple threads through a queue which is read > by an 'after' event running periodically in the main loop. This is similar > to the technique used in many other platforms (e.g., .NET's > InvokeRequired/Invoke mechanism). The technique used in mtTkinter is > exception-safe as well, marshaling exceptions through a response queue back > to the caller's thread. > If a similar technique were employed in _tkinter instead of the polling > technique, that would be a preferable solution. In the meantime, mtTkinter > will work as a good stop-gap measure. > Allen B. Taylor -- -- Guilherme H. Polo Goncalves From callen at gemini.edu Mon Oct 27 19:58:46 2008 From: callen at gemini.edu (C. Allen) Date: Mon, 27 Oct 2008 08:58:46 -1000 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: References: <49009CF6.FA48.005C.0@mdacorporation.com> <4901EA5D.FA48.005C.0@mdacorporation.com> Message-ID: <1225133926.4189.5.camel@phact.hi.gemini.edu> so if you do compile that way, Tk is thread safe, I can have separate mainloops in different threads and they can all post to each others windows, etc? On Fri, 2008-10-24 at 17:45 -0200, Guilherme Polo wrote: > On Fri, Oct 24, 2008 at 5:31 PM, Allen Taylor > wrote: > > Hi Guilherme, > > The versions of Python and Tk used are the default packages installed on > > Linux (Ubuntu 6.06 LTS). I don't know whether the default install is > > compiled with --enable-threads or not. So, mtTkinter seems to be handy if > > you want to use the default installed packages? > > Allen > > > > To check for --enable-threads try this: > > import Tkinter > Tkinter.Tk().getvar("tcl_platform(threaded)") > > You will either get 1, or a TclError. > > Also, I though you said latest tcl/tk versions but clearly tcl/tk > packages in Ubuntu 6.06 are not the latest. > But they also won't make a difference if you didn't recompile python > with these packages, I'm just telling this because right now Ubuntu > includes tcl/tk 8.5 but distributes python-tk compiled against tcl/tk > 8.4. > > Maybe you could include one example where this new module makes a > difference ? We could be talking about different things. For instance, > this: > > import Tkinter > > def test(text_widget): > text_widget.config(text='abcdef') > > def try_it(text_widget): > threading.Thread(target=test, args=(text_widget, )).start() > > lbl = Tkinter.Label() > lbl.pack() > lbl.after(10, lambda: try_it(lbl)) > > lbl.mainloop() > > Would crash if tcl/tk were not compiled with --threads-enabled, but > then using your module it will run just fine. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ggpolo at gmail.com Mon Oct 27 20:57:45 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Mon, 27 Oct 2008 17:57:45 -0200 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: <1225133926.4189.5.camel@phact.hi.gemini.edu> References: <49009CF6.FA48.005C.0@mdacorporation.com> <4901EA5D.FA48.005C.0@mdacorporation.com> <1225133926.4189.5.camel@phact.hi.gemini.edu> Message-ID: On 10/27/08, C. Allen wrote: > > so if you do compile that way, Tk is thread safe, I can have separate > mainloops in different threads and they can all post to each others windows, > etc? No, it doesn't make tk thread safe, it makes tkinter protect access from multiple threads to data in tcl/tk. Also, having multiple mainloops is another story. To have multiple mainloops you would be creating multiple tcl interpreters, which is allowed by tkinter but it will cause all sort of weird errors. Now what you can do when tcl/tk is compiled with --enable-threads and python has thread support too is creating threads in python and changing tk widgets in another thread. tkinter will schedule these calls from other threads to run in the main thread (with a probability to fail). Other toolkits, like qt, require explicit scheduling from the user in these situations, but tkinter tries to do it automatically. > > > On Fri, 2008-10-24 at 17:45 -0200, Guilherme Polo wrote: > On Fri, Oct 24, 2008 at 5:31 PM, Allen Taylor > wrote: > > Hi Guilherme, > > The versions of Python and Tk used are the default packages installed on > > Linux (Ubuntu 6.06 LTS). I don't know whether the default install is > > compiled with --enable-threads or not. So, mtTkinter seems to be handy if > > you want to use the default installed packages? > > Allen > > > > To check for --enable-threads try this: > > import Tkinter > Tkinter.Tk().getvar("tcl_platform(threaded)") > > You will either get 1, or a TclError. > > Also, I though you said latest tcl/tk versions but clearly tcl/tk > packages in Ubuntu 6.06 are not the latest. > But they also won't make a difference if you didn't recompile python > with these packages, I'm just telling this because right now Ubuntu > includes tcl/tk 8.5 but distributes python-tk compiled against tcl/tk > 8.4. > > Maybe you could include one example where this new module makes a > difference ? We could be talking about different things. For instance, > this: > > import Tkinter > > def test(text_widget): > text_widget.config(text='abcdef') > > def try_it(text_widget): > threading.Thread(target=test, args=(text_widget, )).start() > > lbl = Tkinter.Label() > lbl.pack() > lbl.after(10, lambda: try_it(lbl)) > > lbl.mainloop() > > Would crash if tcl/tk were not compiled with --threads-enabled, but > then using your module it will run just fine. > > > -- -- Guilherme H. Polo Goncalves From callen at gemini.edu Tue Oct 28 21:29:36 2008 From: callen at gemini.edu (C. Allen) Date: Tue, 28 Oct 2008 10:29:36 -1000 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: References: <49009CF6.FA48.005C.0@mdacorporation.com> <4901EA5D.FA48.005C.0@mdacorporation.com> <1225133926.4189.5.camel@phact.hi.gemini.edu> Message-ID: <1225225776.20353.8.camel@phact.hi.gemini.edu> Thanks for the explanation Guilherme. Thanks... I see what you mean technically about it not making tk thread safe, but, it makes tkinter's use of tk from python threadsafe (with the mainloop caveat that it's not meant to be run more than once at any rate). On Mon, 2008-10-27 at 17:57 -0200, Guilherme Polo wrote: > On 10/27/08, C. Allen wrote: > > > > so if you do compile that way, Tk is thread safe, I can have separate > > mainloops in different threads and they can all post to each others windows, > > etc? > > No, it doesn't make tk thread safe, it makes tkinter protect access > from multiple threads to data in tcl/tk. > > Also, having multiple mainloops is another story. To have multiple > mainloops you would be creating multiple tcl interpreters, which is > allowed by tkinter but it will cause all sort of weird errors. > > Now what you can do when tcl/tk is compiled with --enable-threads and > python has thread support too is creating threads in python and > changing tk widgets in another thread. tkinter will schedule these > calls from other threads to run in the main thread (with a probability > to fail). > > Other toolkits, like qt, require explicit scheduling from the user in > these situations, but tkinter tries to do it automatically. > > > > > > > On Fri, 2008-10-24 at 17:45 -0200, Guilherme Polo wrote: > > On Fri, Oct 24, 2008 at 5:31 PM, Allen Taylor > > wrote: > > > Hi Guilherme, > > > The versions of Python and Tk used are the default packages installed on > > > Linux (Ubuntu 6.06 LTS). I don't know whether the default install is > > > compiled with --enable-threads or not. So, mtTkinter seems to be handy if > > > you want to use the default installed packages? > > > Allen > > > > > > > To check for --enable-threads try this: > > > > import Tkinter > > Tkinter.Tk().getvar("tcl_platform(threaded)") > > > > You will either get 1, or a TclError. > > > > Also, I though you said latest tcl/tk versions but clearly tcl/tk > > packages in Ubuntu 6.06 are not the latest. > > But they also won't make a difference if you didn't recompile python > > with these packages, I'm just telling this because right now Ubuntu > > includes tcl/tk 8.5 but distributes python-tk compiled against tcl/tk > > 8.4. > > > > Maybe you could include one example where this new module makes a > > difference ? We could be talking about different things. For instance, > > this: > > > > import Tkinter > > > > def test(text_widget): > > text_widget.config(text='abcdef') > > > > def try_it(text_widget): > > threading.Thread(target=test, args=(text_widget, )).start() > > > > lbl = Tkinter.Label() > > lbl.pack() > > lbl.after(10, lambda: try_it(lbl)) > > > > lbl.mainloop() > > > > Would crash if tcl/tk were not compiled with --threads-enabled, but > > then using your module it will run just fine. > > > > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From callen at gemini.edu Tue Oct 28 21:33:29 2008 From: callen at gemini.edu (C. Allen) Date: Tue, 28 Oct 2008 10:33:29 -1000 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: References: <49059F0E.FA48.005C.0@mdacorporation.com> Message-ID: <1225226009.20353.12.camel@phact.hi.gemini.edu> wait a second... I have a class system, and to exercise this class system, and possibly as a general command line tool in the future, I access this class from a script meant to run in a shell. To watch progress of the system as it runs (it's processing data, and can take significant amounts of time) so I thought I'd make a nice little interface to watch the progress, and let the user pause and do other control commands. This is not the purpose of this command line tool, however, so I only bring that up based on a command line flag. Also, I do not call mainloop from the main thread, because it is doing the processing, and is the "real" program. I start another thread, use it (and only it) as the Tk thread. This all works fine, and I never get the exception mentioned below. -craig On Mon, 2008-10-27 at 15:10 -0200, Guilherme Polo wrote: > On Mon, Oct 27, 2008 at 12:59 PM, Allen Taylor > wrote: > > All, > > After a very helpful discussion with "Guilherme Polo ", we > > have come to the following conclusion regarding multithreaded applications > > and Tkinter. Although Tk is technically thread-safe (if built with > > --enable-threads), practically speaking it still has problems when used in > > multithreaded applications. > > Now that I reread it, I see you said "Tk is technically thread-safe > (if built with --enable-threads)". It is not true, what happens is > that tkinter makes it thread safe by using some mutexes and scheduling > actions to go through the thread that created the tcl interpreter, > which otherwise would happen elsewhere. But tk isn't thread safe per > se (only tcl, since version 8.1). At the same time, if tk is > compiled without thread support but python has thread support, then > tkinter fails miserably to protect against multiple threads from > python from accessing tk. > > And again, your module does help in this case since all the > interaction to tk will occur through main thread, independent of tk > having thread support or not. > > > The problem stems from the fact that _tkinter > > attempts to gain control of the main thread via a polling technique. If it > > succeeds, all is well. If it fails, however, the application receives an > > exception with the message "RuntimeError: main thread is not in main loop". > > There is no way to tell when this might happen, so calling Tk routines from > > multiple threads seems to be problematic at best. > > The mtTkinter module I published last week > > (http://tkinter.unpythonic.net/wiki/mtTkinter) solves this problem by > > marshaling calls coming from multiple threads through a queue which is read > > by an 'after' event running periodically in the main loop. This is similar > > to the technique used in many other platforms (e.g., .NET's > > InvokeRequired/Invoke mechanism). The technique used in mtTkinter is > > exception-safe as well, marshaling exceptions through a response queue back > > to the caller's thread. > > If a similar technique were employed in _tkinter instead of the polling > > technique, that would be a preferable solution. In the meantime, mtTkinter > > will work as a good stop-gap measure. > > Allen B. Taylor > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ggpolo at gmail.com Tue Oct 28 21:52:58 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Tue, 28 Oct 2008 18:52:58 -0200 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: <1225226009.20353.12.camel@phact.hi.gemini.edu> References: <49059F0E.FA48.005C.0@mdacorporation.com> <1225226009.20353.12.camel@phact.hi.gemini.edu> Message-ID: On Tue, Oct 28, 2008 at 6:33 PM, C. Allen wrote: > wait a second... I have a class system, and to exercise this class system, > and possibly as a general command line tool in the future, I access this > class from a script meant to run in a shell. To watch progress of the system > as it runs (it's processing data, and can take significant amounts of time) > so I thought I'd make a nice little interface to watch the progress, and let > the user pause and do other control commands. This is not the purpose of > this command line tool, however, so I only bring that up based on a command > line flag. Also, I do not call mainloop from the main thread, because it is > doing the processing, and is the "real" program. I start another thread, > use it (and only it) as the Tk thread. As long as other calls to tk come from the same thread that created the interpreter, there is no need to schedule these calls. > > This all works fine, and I never get the exception mentioned below. The message in that error is more in the sense of "the thread that created the tcl interpreter is not in main loop". It is also very hard to get it with just two threads. It will try ten times, which will last 1 second (as the current implementation), at max, to acquire the thread that created the tcl interpreter, only then if this fails you get that error. > > -craig > > > > On Mon, 2008-10-27 at 15:10 -0200, Guilherme Polo wrote: > > On Mon, Oct 27, 2008 at 12:59 PM, Allen Taylor > wrote: >> All, >> After a very helpful discussion with "Guilherme Polo ", >> we >> have come to the following conclusion regarding multithreaded applications >> and Tkinter. Although Tk is technically thread-safe (if built with >> --enable-threads), practically speaking it still has problems when used in >> multithreaded applications. > > Now that I reread it, I see you said "Tk is technically thread-safe > (if built with --enable-threads)". It is not true, what happens is > that tkinter makes it thread safe by using some mutexes and scheduling > actions to go through the thread that created the tcl interpreter, > which otherwise would happen elsewhere. But tk isn't thread safe per > se (only tcl, since version 8.1). At the same time, if tk is > compiled without thread support but python has thread support, then > tkinter fails miserably to protect against multiple threads from > python from accessing tk. > > And again, your module does help in this case since all the > interaction to tk will occur through main thread, independent of tk > having thread support or not. > >> The problem stems from the fact that _tkinter >> attempts to gain control of the main thread via a polling technique. If it >> succeeds, all is well. If it fails, however, the application receives an >> exception with the message "RuntimeError: main thread is not in main >> loop". >> There is no way to tell when this might happen, so calling Tk routines >> from >> multiple threads seems to be problematic at best. >> The mtTkinter module I published last week >> (http://tkinter.unpythonic.net/wiki/mtTkinter) solves this problem by >> marshaling calls coming from multiple threads through a queue which is >> read >> by an 'after' event running periodically in the main loop. This is similar >> to the technique used in many other platforms (e.g., .NET's >> InvokeRequired/Invoke mechanism). The technique used in mtTkinter is >> exception-safe as well, marshaling exceptions through a response queue >> back >> to the caller's thread. >> If a similar technique were employed in _tkinter instead of the polling >> technique, that would be a preferable solution. In the meantime, mtTkinter >> will work as a good stop-gap measure. >> Allen B. Taylor > > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- -- Guilherme H. Polo Goncalves From callen at gemini.edu Wed Oct 29 03:23:54 2008 From: callen at gemini.edu (C. Allen) Date: Tue, 28 Oct 2008 16:23:54 -1000 Subject: [Tkinter-discuss] Proposal for thread-safe Tkinter In-Reply-To: References: <49059F0E.FA48.005C.0@mdacorporation.com> <1225226009.20353.12.camel@phact.hi.gemini.edu> Message-ID: <1225247034.20353.75.camel@phact.hi.gemini.edu> ah, thanks again Guilherme. That was the principle I was following when I tried to make this well behaved (I'd had a worse, and badly behaved, first version). It was important for Tk not to have the main thread, since the GUI is an addendum for what is generally a command line tool. cheers, craig On Tue, 2008-10-28 at 18:52 -0200, Guilherme Polo wrote: > On Tue, Oct 28, 2008 at 6:33 PM, C. Allen wrote: > > wait a second... I have a class system, and to exercise this class system, > > and possibly as a general command line tool in the future, I access this > > class from a script meant to run in a shell. To watch progress of the system > > as it runs (it's processing data, and can take significant amounts of time) > > so I thought I'd make a nice little interface to watch the progress, and let > > the user pause and do other control commands. This is not the purpose of > > this command line tool, however, so I only bring that up based on a command > > line flag. Also, I do not call mainloop from the main thread, because it is > > doing the processing, and is the "real" program. I start another thread, > > use it (and only it) as the Tk thread. > > As long as other calls to tk come from the same thread that created > the interpreter, there is no need to schedule these calls. > > > > > This all works fine, and I never get the exception mentioned below. > > The message in that error is more in the sense of "the thread that > created the tcl interpreter is not in main loop". It is also very hard > to get it with just two threads. It will try ten times, which will > last 1 second (as the current implementation), at max, to acquire the > thread that created the tcl interpreter, only then if this fails you > get that error. > > > > > -craig > > > > > > > > On Mon, 2008-10-27 at 15:10 -0200, Guilherme Polo wrote: > > > > On Mon, Oct 27, 2008 at 12:59 PM, Allen Taylor > > wrote: > >> All, > >> After a very helpful discussion with "Guilherme Polo ", > >> we > >> have come to the following conclusion regarding multithreaded applications > >> and Tkinter. Although Tk is technically thread-safe (if built with > >> --enable-threads), practically speaking it still has problems when used in > >> multithreaded applications. > > > > Now that I reread it, I see you said "Tk is technically thread-safe > > (if built with --enable-threads)". It is not true, what happens is > > that tkinter makes it thread safe by using some mutexes and scheduling > > actions to go through the thread that created the tcl interpreter, > > which otherwise would happen elsewhere. But tk isn't thread safe per > > se (only tcl, since version 8.1). At the same time, if tk is > > compiled without thread support but python has thread support, then > > tkinter fails miserably to protect against multiple threads from > > python from accessing tk. > > > > And again, your module does help in this case since all the > > interaction to tk will occur through main thread, independent of tk > > having thread support or not. > > > >> The problem stems from the fact that _tkinter > >> attempts to gain control of the main thread via a polling technique. If it > >> succeeds, all is well. If it fails, however, the application receives an > >> exception with the message "RuntimeError: main thread is not in main > >> loop". > >> There is no way to tell when this might happen, so calling Tk routines > >> from > >> multiple threads seems to be problematic at best. > >> The mtTkinter module I published last week > >> (http://tkinter.unpythonic.net/wiki/mtTkinter) solves this problem by > >> marshaling calls coming from multiple threads through a queue which is > >> read > >> by an 'after' event running periodically in the main loop. This is similar > >> to the technique used in many other platforms (e.g., .NET's > >> InvokeRequired/Invoke mechanism). The technique used in mtTkinter is > >> exception-safe as well, marshaling exceptions through a response queue > >> back > >> to the caller's thread. > >> If a similar technique were employed in _tkinter instead of the polling > >> technique, that would be a preferable solution. In the meantime, mtTkinter > >> will work as a good stop-gap measure. > >> Allen B. Taylor > > > > > > > > > > _______________________________________________ > > 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 o.lenstra at gmail.com Wed Oct 29 06:52:11 2008 From: o.lenstra at gmail.com (Olrik Lenstra) Date: Wed, 29 Oct 2008 06:52:11 +0100 Subject: [Tkinter-discuss] WxPython -> Tkinter Message-ID: <3c8f6fd70810282252o166d438fhbf8460233be21a89@mail.gmail.com> Hello everyone, A while ago I joined the Tutor mailing list, and they helped me out with a question regarding wxPython. Now however, I have tried a program in Tkinter and I would like to see if there is a similar command to "wx.SafeYield(self, True)". Below is a copy of the message to the tutor list. Dear Mailing list, > > a while ago a few of you helped me solve an issue I had with a GUI / scan > program that I made. > The problem was that when I tried to move the frame it would hang until the > scan was finished. > To solve this I had to add "wx.SafeYield(self, True)" to the scan and the > GUI wouldn't hang any more. > Now I have redone the program and have written it with Tkinter instead of > WxPython. > > So is there a similar command for Tkinter as there is for WxPython? > > Thanks in advance. > Regards, > Olrik > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ggpolo at gmail.com Wed Oct 29 12:18:21 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 29 Oct 2008 09:18:21 -0200 Subject: [Tkinter-discuss] Fwd: WxPython -> Tkinter In-Reply-To: References: <3c8f6fd70810282252o166d438fhbf8460233be21a89@mail.gmail.com> Message-ID: ---------- Forwarded message ---------- From: Guilherme Polo Date: Oct 29, 2008 9:16 AM Subject: Re: [Tkinter-discuss] WxPython -> Tkinter To: Olrik Lenstra Cc: python-list at python.org On 10/29/08, Olrik Lenstra wrote: > Hello everyone, > > A while ago I joined the Tutor mailing list, and they helped me out with a > question regarding wxPython. > Now however, I have tried a program in Tkinter and I would like to see if > there is a similar command to "wx.SafeYield(self, True)". It will be a combination of commands, not a single one. Initially I considered this as "probably without solution", since tcl acquired a yield command just in the 8.6a3 release, but then I looked at wx.SafeYield code and apparently it is possible to replicate it. Here is an initial cut, it is very possible to contain something not equivalent to wx.SafeYield (besides it could be improved): import ttk inside_tkyield = False disabled_wins = {} def safe_yield(window, only_if_needed=False): window_disabler(window) try: return tk_yield(window, only_if_needed) finally: for widget, flags in disabled_wins.iteritems(): ttk.Widget.state(widget, flags) disabled_wins.clear() def window_disabler(window): widgets = window.children.values() widgets.append(window) for widget in widgets: if widget.instate(['!disabled']): prev_flags = widget.state(['disabled']) disabled_wins[widget] = prev_flags def tk_yield(window, only_if_needed=False): # wx implements this differently based on the backend it is using global inside_tkyield if inside_tkyield: if not only_if_needed: raise RuntimeError("safe_yield called recursively") return False inside_tkyield = True; window.update() window.update_idletasks() inside_tkyield = False; return True Note that this depends on ttk widgets (http://pypi.python.org/pypi/pyttk) since it uses widget.state to disable and reenable the widgets. On windows the "wm" command supports disabling the entire window, so it is easier if you can use it. [Forwarded because I sent to the wrong list first time] > Below is a copy of the message to the tutor list. > > > Dear Mailing list, > > > > a while ago a few of you helped me solve an issue I had with a GUI / scan > > program that I made. > > The problem was that when I tried to move the frame it would hang until > the > > scan was finished. > > To solve this I had to add "wx.SafeYield(self, True)" to the scan and the > > GUI wouldn't hang any more. > > Now I have redone the program and have written it with Tkinter instead of > > WxPython. > > > > So is there a similar command for Tkinter as there is for WxPython? > > > > Thanks in advance. > > Regards, > > Olrik > > > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > > -- -- Guilherme H. Polo Goncalves -- -- Guilherme H. Polo Goncalves From o.lenstra at gmail.com Wed Oct 29 14:49:28 2008 From: o.lenstra at gmail.com (Olrik Lenstra) Date: Wed, 29 Oct 2008 14:49:28 +0100 Subject: [Tkinter-discuss] Fwd: WxPython -> Tkinter In-Reply-To: References: <3c8f6fd70810282252o166d438fhbf8460233be21a89@mail.gmail.com> Message-ID: <3c8f6fd70810290649madf53e2q1fcc1acd21f6bfff@mail.gmail.com> I see, Thanks a lot, I really don't wish to bother you any further, but here's my current situation. I am still a beginning programmer and I am not entirely sure where to put this code exactly. How would I go about using this code? Thank you so much in advance. Regards, Olrik 2008/10/29 Guilherme Polo > ---------- Forwarded message ---------- > From: Guilherme Polo > Date: Oct 29, 2008 9:16 AM > Subject: Re: [Tkinter-discuss] WxPython -> Tkinter > To: Olrik Lenstra > Cc: python-list at python.org > > > On 10/29/08, Olrik Lenstra wrote: > > Hello everyone, > > > > A while ago I joined the Tutor mailing list, and they helped me out with > a > > question regarding wxPython. > > Now however, I have tried a program in Tkinter and I would like to see > if > > there is a similar command to "wx.SafeYield(self, True)". > > > It will be a combination of commands, not a single one. Initially I > considered this as "probably without solution", since tcl acquired a > yield command just in the 8.6a3 release, but then I looked at > wx.SafeYield code and apparently it is possible to replicate it. > > Here is an initial cut, it is very possible to contain something not > equivalent to wx.SafeYield (besides it could be improved): > > > import ttk > > inside_tkyield = False > disabled_wins = {} > > def safe_yield(window, only_if_needed=False): > window_disabler(window) > > try: > return tk_yield(window, only_if_needed) > finally: > for widget, flags in disabled_wins.iteritems(): > ttk.Widget.state(widget, flags) > disabled_wins.clear() > > > def window_disabler(window): > widgets = window.children.values() > widgets.append(window) > > for widget in widgets: > if widget.instate(['!disabled']): > prev_flags = widget.state(['disabled']) > disabled_wins[widget] = prev_flags > > > def tk_yield(window, only_if_needed=False): > # wx implements this differently based on the backend it is using > global inside_tkyield > if inside_tkyield: > if not only_if_needed: > raise RuntimeError("safe_yield called recursively") > > return False > > inside_tkyield = True; > > window.update() > window.update_idletasks() > > inside_tkyield = False; > > return True > > > Note that this depends on ttk widgets > (http://pypi.python.org/pypi/pyttk) since it uses widget.state to > disable and reenable the widgets. On windows the "wm" command supports > disabling the entire window, so it is easier if you can use it. > > [Forwarded because I sent to the wrong list first time] > > > Below is a copy of the message to the tutor list. > > > > > Dear Mailing list, > > > > > > a while ago a few of you helped me solve an issue I had with a GUI / > scan > > > program that I made. > > > The problem was that when I tried to move the frame it would hang > until > > the > > > scan was finished. > > > To solve this I had to add "wx.SafeYield(self, True)" to the scan and > the > > > GUI wouldn't hang any more. > > > Now I have redone the program and have written it with Tkinter instead > of > > > WxPython. > > > > > > So is there a similar command for Tkinter as there is for WxPython? > > > > > > Thanks in advance. > > > Regards, > > > Olrik > > > > > > > > _______________________________________________ > > Tkinter-discuss mailing list > > Tkinter-discuss at python.org > > http://mail.python.org/mailman/listinfo/tkinter-discuss > > > > > > > > -- > -- Guilherme H. Polo Goncalves > > > -- > -- Guilherme H. Polo Goncalves > _______________________________________________ > 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 ggpolo at gmail.com Wed Oct 29 14:55:59 2008 From: ggpolo at gmail.com (Guilherme Polo) Date: Wed, 29 Oct 2008 11:55:59 -0200 Subject: [Tkinter-discuss] Fwd: WxPython -> Tkinter In-Reply-To: <3c8f6fd70810290649madf53e2q1fcc1acd21f6bfff@mail.gmail.com> References: <3c8f6fd70810282252o166d438fhbf8460233be21a89@mail.gmail.com> <3c8f6fd70810290649madf53e2q1fcc1acd21f6bfff@mail.gmail.com> Message-ID: On 10/29/08, Olrik Lenstra wrote: > I see, Thanks a lot, I really don't wish to bother you any further, but > here's my current situation. > I am still a beginning programmer and I am not entirely sure where to put > this code exactly. > > How would I go about using this code? > It should be very similar to what you are already doing in wx. But, you would need to layout your toplevel (the one that is created when you call Tkinter.Tk()) as this: There would be a ttk.Frame that would hold all the other widgets, which should be all ttk widgets according to this sample. Then you would call safe_yield(frame, True) in the same situations you would in wx. Now it remains to check if there is the same need for this in tk as there is in wx. Finally, a sample way to layout the widgets: root = Tkinter.Tk() frame = ttk.Frame(root) btn1 = ttk.Button(frame, text="Button 1") ... ... some time later: safe_yield(frame, True) ... > Thank you so much in advance. > Regards, > Olrik > > 2008/10/29 Guilherme Polo > > > > > > > > > ---------- Forwarded message ---------- > > From: Guilherme Polo > > Date: Oct 29, 2008 9:16 AM > > Subject: Re: [Tkinter-discuss] WxPython -> Tkinter > > To: Olrik Lenstra > > Cc: python-list at python.org > > > > > > On 10/29/08, Olrik Lenstra wrote: > > > Hello everyone, > > > > > > A while ago I joined the Tutor mailing list, and they helped me out > with a > > > question regarding wxPython. > > > Now however, I have tried a program in Tkinter and I would like to see > if > > > there is a similar command to "wx.SafeYield(self, True)". > > > > > > It will be a combination of commands, not a single one. Initially I > > considered this as "probably without solution", since tcl acquired a > > yield command just in the 8.6a3 release, but then I looked at > > wx.SafeYield code and apparently it is possible to replicate it. > > > > Here is an initial cut, it is very possible to contain something not > > equivalent to wx.SafeYield (besides it could be improved): > > > > > > import ttk > > > > inside_tkyield = False > > disabled_wins = {} > > > > def safe_yield(window, only_if_needed=False): > > window_disabler(window) > > > > try: > > return tk_yield(window, only_if_needed) > > finally: > > for widget, flags in disabled_wins.iteritems(): > > ttk.Widget.state(widget, flags) > > disabled_wins.clear() > > > > > > def window_disabler(window): > > widgets = window.children.values() > > widgets.append(window) > > > > for widget in widgets: > > if widget.instate(['!disabled']): > > prev_flags = widget.state(['disabled']) > > disabled_wins[widget] = prev_flags > > > > > > def tk_yield(window, only_if_needed=False): > > # wx implements this differently based on the backend it is using > > global inside_tkyield > > if inside_tkyield: > > if not only_if_needed: > > raise RuntimeError("safe_yield called recursively") > > > > return False > > > > inside_tkyield = True; > > > > window.update() > > window.update_idletasks() > > > > inside_tkyield = False; > > > > return True > > > > > > Note that this depends on ttk widgets > > (http://pypi.python.org/pypi/pyttk) since it uses > widget.state to > > disable and reenable the widgets. On windows the "wm" command supports > > disabling the entire window, so it is easier if you can use it. > > > > [Forwarded because I sent to the wrong list first time] > > > > > > > Below is a copy of the message to the tutor list. > > > > > > > Dear Mailing list, > > > > > > > > a while ago a few of you helped me solve an issue I had with a GUI / > scan > > > > program that I made. > > > > The problem was that when I tried to move the frame it would hang > until > > > the > > > > scan was finished. > > > > To solve this I had to add "wx.SafeYield(self, True)" to the scan and > the > > > > GUI wouldn't hang any more. > > > > Now I have redone the program and have written it with Tkinter > instead of > > > > WxPython. > > > > > > > > So is there a similar command for Tkinter as there is for WxPython? > > > > > > > > Thanks in advance. > > > > Regards, > > > > Olrik > > > > > > > > > > > > _______________________________________________ > > > Tkinter-discuss mailing list > > > Tkinter-discuss at python.org > > > > http://mail.python.org/mailman/listinfo/tkinter-discuss > > > > > > > > > > > > > > -- > > -- Guilherme H. Polo Goncalves > > > > > > -- > > -- Guilherme H. Polo Goncalves > > > > > > > > _______________________________________________ > > Tkinter-discuss mailing list > > Tkinter-discuss at python.org > > > http://mail.python.org/mailman/listinfo/tkinter-discuss > > > > -- -- Guilherme H. Polo Goncalves From o.lenstra at gmail.com Wed Oct 29 15:23:33 2008 From: o.lenstra at gmail.com (Olrik Lenstra) Date: Wed, 29 Oct 2008 15:23:33 +0100 Subject: [Tkinter-discuss] Fwd: WxPython -> Tkinter In-Reply-To: References: <3c8f6fd70810282252o166d438fhbf8460233be21a89@mail.gmail.com> <3c8f6fd70810290649madf53e2q1fcc1acd21f6bfff@mail.gmail.com> Message-ID: <3c8f6fd70810290723u561ed191s31dec5b9ad9f7213@mail.gmail.com> So that means that you will use a ttk frame instead of the Tkinter.Frame? I'll see if I can get this working once I get home. (my program is on my Desktop and I just do some testing on my laptop) Thanks a lot so far! Regards, Olrik 2008/10/29 Guilherme Polo > On 10/29/08, Olrik Lenstra wrote: > > I see, Thanks a lot, I really don't wish to bother you any further, but > > here's my current situation. > > I am still a beginning programmer and I am not entirely sure where to put > > this code exactly. > > > > How would I go about using this code? > > > > It should be very similar to what you are already doing in wx. > > But, you would need to layout your toplevel (the one that is created > when you call Tkinter.Tk()) as this: > > There would be a ttk.Frame that would hold all the other widgets, > which should be all ttk widgets according to this sample. Then you > would call safe_yield(frame, True) in the same situations you would in > wx. Now it remains to check if there is the same need for this in tk > as there is in wx. > > Finally, a sample way to layout the widgets: > > root = Tkinter.Tk() > frame = ttk.Frame(root) > btn1 = ttk.Button(frame, text="Button 1") > ... > ... some time later: > safe_yield(frame, True) > ... > > > Thank you so much in advance. > > Regards, > > Olrik > > > > 2008/10/29 Guilherme Polo > > > > > > > > > > > > > > ---------- Forwarded message ---------- > > > From: Guilherme Polo > > > Date: Oct 29, 2008 9:16 AM > > > Subject: Re: [Tkinter-discuss] WxPython -> Tkinter > > > To: Olrik Lenstra > > > Cc: python-list at python.org > > > > > > > > > On 10/29/08, Olrik Lenstra wrote: > > > > Hello everyone, > > > > > > > > A while ago I joined the Tutor mailing list, and they helped me out > > with a > > > > question regarding wxPython. > > > > Now however, I have tried a program in Tkinter and I would like to > see > > if > > > > there is a similar command to "wx.SafeYield(self, True)". > > > > > > > > > It will be a combination of commands, not a single one. Initially I > > > considered this as "probably without solution", since tcl acquired a > > > yield command just in the 8.6a3 release, but then I looked at > > > wx.SafeYield code and apparently it is possible to replicate it. > > > > > > Here is an initial cut, it is very possible to contain something not > > > equivalent to wx.SafeYield (besides it could be improved): > > > > > > > > > import ttk > > > > > > inside_tkyield = False > > > disabled_wins = {} > > > > > > def safe_yield(window, only_if_needed=False): > > > window_disabler(window) > > > > > > try: > > > return tk_yield(window, only_if_needed) > > > finally: > > > for widget, flags in disabled_wins.iteritems(): > > > ttk.Widget.state(widget, flags) > > > disabled_wins.clear() > > > > > > > > > def window_disabler(window): > > > widgets = window.children.values() > > > widgets.append(window) > > > > > > for widget in widgets: > > > if widget.instate(['!disabled']): > > > prev_flags = widget.state(['disabled']) > > > disabled_wins[widget] = prev_flags > > > > > > > > > def tk_yield(window, only_if_needed=False): > > > # wx implements this differently based on the backend it is using > > > global inside_tkyield > > > if inside_tkyield: > > > if not only_if_needed: > > > raise RuntimeError("safe_yield called recursively") > > > > > > return False > > > > > > inside_tkyield = True; > > > > > > window.update() > > > window.update_idletasks() > > > > > > inside_tkyield = False; > > > > > > return True > > > > > > > > > Note that this depends on ttk widgets > > > (http://pypi.python.org/pypi/pyttk) since it uses > > widget.state to > > > disable and reenable the widgets. On windows the "wm" command supports > > > disabling the entire window, so it is easier if you can use it. > > > > > > [Forwarded because I sent to the wrong list first time] > > > > > > > > > > Below is a copy of the message to the tutor list. > > > > > > > > > Dear Mailing list, > > > > > > > > > > a while ago a few of you helped me solve an issue I had with a GUI > / > > scan > > > > > program that I made. > > > > > The problem was that when I tried to move the frame it would hang > > until > > > > the > > > > > scan was finished. > > > > > To solve this I had to add "wx.SafeYield(self, True)" to the scan > and > > the > > > > > GUI wouldn't hang any more. > > > > > Now I have redone the program and have written it with Tkinter > > instead of > > > > > WxPython. > > > > > > > > > > So is there a similar command for Tkinter as there is for > WxPython? > > > > > > > > > > Thanks in advance. > > > > > Regards, > > > > > Olrik > > > > > > > > > > > > > > > > _______________________________________________ > > > > Tkinter-discuss mailing list > > > > Tkinter-discuss at python.org > > > > > > http://mail.python.org/mailman/listinfo/tkinter-discuss > > > > > > > > > > > > > > > > > > > > -- > > > -- Guilherme H. Polo Goncalves > > > > > > > > > -- > > > -- Guilherme H. Polo Goncalves > > > > > > > > > > > > _______________________________________________ > > > Tkinter-discuss mailing list > > > Tkinter-discuss at python.org > > > > > http://mail.python.org/mailman/listinfo/tkinter-discuss > > > > > > > > > > -- > -- Guilherme H. Polo Goncalves > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Allen.Taylor at mdacorporation.com Wed Oct 29 16:45:04 2008 From: Allen.Taylor at mdacorporation.com (Allen Taylor) Date: Wed, 29 Oct 2008 11:45:04 -0400 Subject: [Tkinter-discuss] mtTkinter version 0.2 uploaded Message-ID: <49084CC0.FA48.005C.0@mdacorporation.com> Fixed some fairly major bugs and uploaded to http://tkinter.unpythonic.net/wiki/mtTkinter. Allen -------------- next part -------------- An HTML attachment was scrubbed... URL: