Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > tkinter, sockets and threads together

Reply
Thread Tools

tkinter, sockets and threads together

 
 
Julia Goolia
Guest
Posts: n/a
 
      09-11-2003
hello,

i read that it is bad to use threads with tkinter. so my question is
how does one create a gui program with sockets? at one point you have
to call mainloop() which does not return. then you are not free to do
stuff with the sockets.

what's up with that?

thanks so much for your time!
julia
 
Reply With Quote
 
 
 
 
Russell E. Owen
Guest
Posts: n/a
 
      09-11-2003
In article <(E-Mail Removed) >,
http://www.velocityreviews.com/forums/(E-Mail Removed) (Julia Goolia) wrote:

>hello,
>
>i read that it is bad to use threads with tkinter. so my question is
>how does one create a gui program with sockets? at one point you have
>to call mainloop() which does not return. then you are not free to do
>stuff with the sockets.
>
>what's up with that?


For reading from a socket you can use file events. See Tkinter Summary
at my site <http://www.astro.washington.edu/owen/> for the basics.

To avoid blocking while writing (i.e.queue up the output data and write
it as the network permits), I ended up using threads. There are probably
other options.

The package "RO Util", available at th web site mentioned above includes
a simple class RO.Comm.TkSocket that handles input and output nicely,
while hiding the details of file events and the writing thread.

You could also use the Twisted Framework. It is reportedly well done and
integrate nicely with Tkinter and other frameworks. I can't speak from
personal experience as I've not yet tried it.

-- Russell
 
Reply With Quote
 
 
 
 
Martin v. =?iso-8859-15?q?L=F6wis?=
Guest
Posts: n/a
 
      09-11-2003
(E-Mail Removed) (Julia Goolia) writes:

> i read that it is bad to use threads with tkinter. so my question is
> how does one create a gui program with sockets? at one point you have
> to call mainloop() which does not return. then you are not free to do
> stuff with the sockets.
>
> what's up with that?


On Unix, you can use Tk file handlers for sockets, i.e. have Tcl
select(2) not only on the connection to the X11 server (which is a
socket itself), but also select on your sockets. This is readily
supported in _tkinter.

On Windows, you have no choice but to use threads. If the socket
processing threads have no relationship to the Tk thread, everything
is fine. However, in many cases, interaction of some kind is
needed. In this case, it is ok to call Tk methods from other threads,
as long as they translate to "fast" commands, i.e. commands that only
modify state, but don't block - you should not run the mainloop in
multiple threads.

Regards,
Martin

 
Reply With Quote
 
Richard Townsend
Guest
Posts: n/a
 
      09-11-2003
> i read that it is bad to use threads with tkinter. so my question is
> how does one create a gui program with sockets? at one point you have
> to call mainloop() which does not return. then you are not free to do
> stuff with the sockets.
>


Take a look at
http://www.python.org/doc/faq/gui.ht...ndled-while-wa
iting-for-i-o


RT



 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      09-12-2003
"Julia Goolia" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> hello,
>
> i read that it is bad to use threads with tkinter. so my question is
> how does one create a gui program with sockets? at one point you have
> to call mainloop() which does not return. then you are not free to do
> stuff with the sockets.
>
> what's up with that?
>
> thanks so much for your time!


Well, one page worth reading would be Jacob HallÚn's

http://aspn.activestate.com/ASPN/Coo...n/Recipe/82965

recipe, which IIRC is pretty general.

regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/




 
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
Using rmi and custom sockets together VisionSet Java 0 11-11-2005 04:08 PM
Possible to combine the "I like B&H, but" and the "B&H Closed" threads together Steven Wandy Digital Photography 4 10-29-2005 08:11 AM
tkinter, threads and asyncore together george.trojan@noaa.gov Python 5 02-12-2004 01:24 PM
Help needed in problem with Threads and sockets. Gonšalo Rodrigues Python 0 12-29-2003 07:39 PM
Threads and Sockets Jupiter5F C++ 4 11-14-2003 09:43 PM



Advertisments