Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter and threads

Reply
Thread Tools

Tkinter and threads

 
 
Boman Romain
Guest
Posts: n/a
 
      05-04-2004
Hi everyone,
I've got problems with Tkinter and threads when using a debug version of
python.
I would like to build a "GUI thread" and an "interpreter thread" (the
classical python command line). Both threads don't interact with each other
(for now).
The GUI must be in a separate thread because the user can execute commands
that take a long time to run through the command line (and the GUI must be
available during these commands)

For example: (file: mygui.py)

import threading
import Tkinter

class RWin (threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self, *args):
self.root = Tkinter.Tk()
print 'starting Tk!'
self.root.mainloop()

bw = RWin()
bw.start()


when I load this file (import mygui), the tk window opens and everything is
OK if I use a non-debug version of python.
Otherwise (with a debug version), python_d crashes when I press a key with
this message : "Fatal python error: invalid thread state for this thread"

It seams that the problem comes from the EventHook() function defined by
tkinter. This function is called by the main thread (the interpreter)
because tkinter uses PyOS_InputHook (for managing things I don't
understand). This function calls RestoreThread() with the Tk thread state
instead of the main thread state. As the debug version checks these states,
it fails.

What is wrong? Is it impossible to have these two threads working toegether
(in a debug version of python)?


Romain


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[new to threads] threads with UI and loop Une bévue Ruby 0 06-14-2006 10:22 AM
tkinter and threads Nir Aides Python 1 05-04-2005 01:39 PM
threads, sockets, pyopengl, pickle (and tkinter...) Rod Stephenson Python 0 06-22-2004 03:37 AM
tkinter, threads and asyncore together george.trojan@noaa.gov Python 5 02-12-2004 01:24 PM
tkinter, sockets and threads together Julia Goolia Python 4 09-12-2003 11:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57