Hi! Well...you CAN do things to a GUI from a thread in Tkinter, but not on Windows (and, of course, not on Linux, Solaris or OSX just because you're not supposed to in the first place).
I had, in essence: Stop = False def TickleButton(But): while Stop == False: sleep(.25) But.update() return StopBut = None def drawForm(): global StopBut Entry fields, Labels, Buttons, Texts, etc... StopBut = Button(text = "Stop", command = change Stop to True) return # Do stuff and output info to a Text field or draw on a Canvas. def doSomethingLongAndTedious(): start_new_thread(TickleButton, (StopBut)) Do lots of stuff while checking the value of Stop when appropriate. When finished Stop = True return At some point call drawForm() and bring up the form (usually a menu command in my case). At some point call doSomethingLongAndTedious() (usually from a GO button on the form in my case). Everything works fine, except on Windows. If the Button is on a form (form=a Frame with buttons, fields, Labels, etc.) that has a Text widget or a Canvas widget with Scrollbars (vertical in my case) attached to them everything is fine UNTIL the Text or Canvas gets full enough with output from the operation in the long and tedious function) to activate the Scrollbars. Then at that instant everything grinds to a severe halt (you have to practically use the Task Manager to kill the program). It's odd that it's OK on *NIXs, but not on Windows. I wouldn't know if it is a Tkinter problem, or a Python problem, or just a Scrollbar problem, or what (I'm not that smart). Is it ever going to be possible to do things like this? What with multiple core CPUs and many threads and stuff now upon us Tkinter is beginning to show signs of death, which is too bad since it runs like crazy everywhere with minimal fuss. So I'm back to just calling But.update() every once-in-a-while in the programs. It works OK, but not as well as I'd like. It's tricky figuring out in each long and scary function when to do the update (don't want to do it too often or it slows things down, but don't want to do it too slowly or the user thinks nothing is happening when they click the Stop button -- my Stop buttons go from red/NORMAL when running to yellow when the user clicks on them then to default color/ DISABLED when the long and tedious function actually gets to a safe stopping point). Bob On the EeePC signals thing, it doesn't look like the programs get any signals when the lid is closed and the Linux goes into standby (which makes some sense -- the programs aren't really supposed to know that anything happened when you go into standby), but there are little one- liner text files that get changed from things like "Lid: open" to "Lid: closed" that I can poll (again, polling! :) to see when the lid has been closed and shutdown the serial ports in time...maybe. I haven't gotten back to that program to implement it yet. On Jan 23, 2008, at 03:50, [EMAIL PROTECTED] wrote: > > Hello Bob, > > You wrote: >> Is there anything that is OK for a thread to do to the GUI? Like >> would just calling .update() on a Button() be OK? It seems to work, >> but is it OK? > >> I'm calling it on a "Stop" button, specifically, in the thread every >> quarter second, instead of peppering the code with updates() to give >> the button a chance to set it's IntVar value and then stop everything >> when the code gets around to checking that. > >> From what I remember everybody says: Don't do that! > Some refs I found googling for 'tkinter and threads': > > A clear warning > http://mail.python.org/pipermail/tkinter-discuss/2005-February/ > 000313.html > (the cited reference is dead, though) > In the following answer is a small example using threading. > > Another example using thread and Queue (from effbot): > http://effbot.org/zone/tkinter-threads.htm > > I have used a solution from Mark Lutz (Programming Python/O'Reilly) > but just for popup dialogs that block the GUI while a thread > is running (communicating via a simple variable). > This might be applicable to your scenario, too. > > In a socket testing application I have used 'after' in the GUI thread > to look at a common buffer if new data have arrived. > > > BTW have you found some info regarding your signals problem? > > Hope this helps, > Matthias Kievernagel > (mkiever/at/web/dot/de) > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss@python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss