473,387 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

"RuntimeError: Calling Tcl from different appartment"

I am writing a multi-threaded Tkinter application. It worked fine with
Python 2.2 under Redhat 8.0, but I have recently moved across to
Debian (testing/unstable) and Python 2.3. Now I get the above error
message.

I read on this group somewhere that this is caused by calling Tk
functions from a different thread to where the interface is running.
Unfortunately, I really need to do this and cannot have all my Tk
calls within one thread. Is there a way around this? Why did it work
in 2.2 but not 2.3?

Thanks,

Peter
Jul 18 '05 #1
3 8512
In article <ce**************************@posting.google.com >,
Peter Saffrey <th*******@my-deja.com> wrote:

I am writing a multi-threaded Tkinter application. It worked fine with
Python 2.2 under Redhat 8.0, but I have recently moved across to
Debian (testing/unstable) and Python 2.3. Now I get the above error
message.

I read on this group somewhere that this is caused by calling Tk
functions from a different thread to where the interface is running.
Yup.
Unfortunately, I really need to do this and cannot have all my Tk
calls within one thread. Is there a way around this? Why did it work
in 2.2 but not 2.3?


No clue why it used to work. Why do you need to call Tk from multiple
threads?
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"Typing is cheap. Thinking is expensive." --Roy Smith, c.l.py
Jul 18 '05 #2
aa**@pythoncraft.com (Aahz) wrote in message news:<cb**********@panix1.panix.com>...
In article <ce**************************@posting.google.com >,
Peter Saffrey <th*******@my-deja.com> wrote:

No clue why it used to work. Why do you need to call Tk from multiple
threads?


I'm writing an MP3 jukebox (don't laugh, it's just for fun). One
thread controls the interface that shows the next few songs to be
played and allows you to add to the list. The other thread plays the
songs, removing them from the list in the process. To control this
with one thread, I'd have to have the interface thread constantly
listening for when the last song has finished so that it can remove it
from the list and play the next one.

Peter
Jul 18 '05 #3
Peter Saffrey wrote:
aa**@pythoncraft.com (Aahz) wrote in message news:<cb**********@panix1.panix.com>...
In article <ce**************************@posting.google.com >,
Peter Saffrey <th*******@my-deja.com> wrote:

No clue why it used to work. Why do you need to call Tk from multiple
threads?

I'm writing an MP3 jukebox (don't laugh, it's just for fun). One
thread controls the interface that shows the next few songs to be
played and allows you to add to the list. The other thread plays the
songs, removing them from the list in the process. To control this
with one thread, I'd have to have the interface thread constantly
listening for when the last song has finished so that it can remove it
from the list and play the next one.


No you don't. There's one thing you can do in secondary threads wrt to Tkinter:
posting events in Tkinter event queue via the event_generate method. Here is an
example:

--tkinterNThreads.py-----------------------------------------
import threading, time
from Tkinter import *

root = Tk()

def ping():
while 1:
time.sleep(1)
root.event_generate('<<Ping>>', when='tail')

v = BooleanVar()
v.set(0)
Checkbutton(root, variable=v, text='Ping!').pack(side=TOP)
Button(root, text='Quit', command=root.quit).pack(side=TOP)

def gotPing(event):
v.set(not v.get())

root.bind('<<Ping>>', gotPing)

th = threading.Thread(target=ping)
th.setDaemon(1)
th.start()

root.mainloop()
-------------------------------------------------------------

The secondary thread make the check-button blink by generating custom <<Ping>>
events in Tkinter event queue. Note the option when='tail' in event_generate is
mandatory: if you don't set it, there's a chance that the event is treated
immediatly without switching threads.

The code above works on Linux and Windows (there are other issues on Solaris,
but I assume it won't be your target platform...)

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Bobbitt | last post by:
I've recently decided to switch from compiled Apache/PHP to RPM's of both and I'm having a problem I can't seem to solve. I have a Perl script called php_include.cgi that parses a PHP file for...
5
by: Al Christoph | last post by:
I have a program that mixes wizard like behavior with random access to the various dialogs in the wizard. I do this by having each step map to a toolstripmenuitem. Users can randomly choose the...
4
by: jr | last post by:
I am working in VC++ so this may be microsoft specific though I don't think so. Excuse me if it is. Assuming it isn't, can someone generally explain the purpose of having both - is it purely a...
4
by: Jerry Krinock | last post by:
I've written the following demo to help me understand a problem I'm having in a larger program. The "main" function constructs a Foo object, and then later "reconstructs" it by calling the...
4
by: kinne | last post by:
The following code is supposed to reverse the date in "yyyy-mm-dd" format, but it produces different results in Firefox 1.0 and in Internet Explorer 6SP1. In Firefox, the result is correct...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
11
by: jobs239 | last post by:
Can I use this line inside C program "system(java -jar <jarfilename>)" to run a java program from C? Or do I have to use some JNI interface.?
3
by: Jukka K. Korpela | last post by:
Some time ago in this group, someone suggested that we should develop a "different" user style sheet to demonstrate what a user style sheet or a browser style sheet _could_ do. I guess the idea was...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.