473,587 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter / Threads: "Invalid command name"

I know, questions about Tkinter and threads have been answered very
often, but I want to ask anyway.
I am using Python 2.2 on a Linux (SuSE Linux 8.1) system.
I want to write a server application; like telnet is a client. The user
should be able to bind() to a port and wait for a client. The written
and recieved data is stored in a Text widget, self.__text. The
accept()ing is done in a seperate thread (using the threading module),
in method self.__tryConne ct().
But the seperate thread raises an exception at
self.__text["state"]="normal" .
A part of the code:

def go(self, portn):
# Open the window and connect.

# Bind self.__server to ("", portn), call listen(), ...

# When everything's ok, start the accept()ing thread.
thr=threading.T hread(target=se lf.__tryConnect )
thr.start()

def __tryConnect(se lf):
# Accept a connection
success=1
self.__text["state"]="normal" # Here the exception is raised
self.__text.ins ert("end", "Waiting for connection... ")
try: self.__client, addr=self.__ser ver.accept()
except: success=0
if not success:
self.__text.ins ert("end", "failed.\n" )
else:
self.__text.ins ert("end", "ok, connected with %s.\n" % addr[0])
self.__text["state"]="disabled"

But when I join() the thread, everything works as it should. Eventually
the self.__text reference is lost when __tryConnect() returns?
The exception is:

Exception in thread Thread-1:
Traceback (most recent call last):
...
File "...", line xx, in configure:
self.tk.call((s elf.w, configure)
TclError: invalid command name ".123123123.123 41234" ,

while ".123123123.123 41234" is the text widgets identification.
Can anyone help me?

Michael Schutte <m.*******@aon. at>
Jul 18 '05 #1
2 6229
In article <3f************ ***********@new sreader01.highw ay.telekom.at>,
Michael Schutte <m.*******@aon. at> wrote:
...I want to write a server application; like telnet is a client. The user
should be able to bind() to a port and wait for a client. The written
and recieved data is stored in a Text widget, self.__text. The
accept()ing is done in a seperate thread (using the threading module),
in method self.__tryConne ct().
But the seperate thread raises an exception at
self.__text["state"]="normal" .
A part of the code:


You should only deal with Tkinter from the main thread.

(That was most certainly true in the past. I'm not quite positive that
it is still supposed to be true, but I can assure you that it doesn't
work well on my system.)

I suggest you use a Lock or Queue or some other inter-thread
communication object to let the accept thread communicate with the rest
of the application.

-- Russell

(You might also want to use Twisted framework.)
Jul 18 '05 #2
Russell E. Owen wrote:
In article <3f************ ***********@new sreader01.highw ay.telekom.at>,
Michael Schutte <m.*******@aon. at> wrote:

...I want to write a server application; like telnet is a client. The user
should be able to bind() to a port and wait for a client. The written
and recieved data is stored in a Text widget, self.__text. The
accept()ing is done in a seperate thread (using the threading module),
in method self.__tryConne ct().
But the seperate thread raises an exception at
self.__text["state"]="normal" .
A part of the code:

You should only deal with Tkinter from the main thread.

(That was most certainly true in the past. I'm not quite positive that
it is still supposed to be true, but I can assure you that it doesn't
work well on my system.)

I suggest you use a Lock or Queue or some other inter-thread
communication object to let the accept thread communicate with the rest
of the application.


I usually use the event_generate method with custom events on Tkinter widgets
from secondary threads to report events to the main thread. This seems to work
well on all platforms I've worked with (Linux, Windows, Solaris). The
communication via a Lock or Queue is a bit less "natural", since you have to
check regularly if a secondary thread tries to tell you something.

My ¤0.02. HTH.
--
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #3

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

Similar topics

0
4597
by: Brian Morris | last post by:
I'm new to .NET and just trying a few things out, like emailing. I created a form in Visual Studio .Net to input some information for generating an email and I'm getting the following error when it executes both on my server or on the server of the .NET service provider. I'm obviously missing something very basic and I'm hoping one of you can...
1
3867
by: Ron | last post by:
I am trying to run asp.net pages. The server is accessed via http://sitename/username I have verified it is using port 80 and aspx extensions are configured. But when I run and asp.net page I get the following error: Invalid file name for monitoring: 'E:\'. File names for monitoring must have absolute paths, and no wildcards....
2
22770
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F: operator delete(void*) (vg_replace_malloc.c:156) ==11604== by 0x804A1BA: __gnu_cxx::new_allocator<Foo>::deallocate(Foo*, unsigned)...
6
13585
by: TS | last post by:
Hi, i have a problem validating xml against schema. I used http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx validator and it says it is fine. Can you tell me why this doesn't work? Thanks! Schema: <?xml version="1.0"?> <xs:schema id="ReportInfo" targetNamespace="http://tempuri.org/Reports.xsd"
1
4165
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two...
6
6711
by: Clément Collin | last post by:
I working on a GIS project, with Access link which just need a little routine in VBA, but I haven't knowledges in VBA language. It's very simple, and it looks like that in a TPascal way : .... Var RecordNb : integer ; .... {Command : function of Access}
1
5214
by: Gregor Horvath | last post by:
Hi, I searched the web and docs but cannot figure out whats wrong with this code: #!/usr/bin/python import Tkinter as Tk class testtk(Tk.Frame):
8
6277
by: lawrence k | last post by:
I've installed Apache 1.3.36 on my Redhat EL 3 machine. Now I'm trying to install PHP 5.1.4. I can not get the ./configure command to work. I keep getting this error: configure: error: Invalid Apache directory - unable to find httpd.h under /usr/local/apache/include So then I run this command: find / -name httpd.h
1
8012
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL: http://(address.of.my.webcam):port/LiveView.html and
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.