Waiting for Connection
Kent Johnson
kent at kentsjohnson.com
Mon Feb 27 11:51:56 EST 2006
D wrote:
> I am trying to do the following using Python and Tkinter:
>
> 1) Display a window with 1 button
> 2) When user clicks the button, Python attempts to call a function
> that opens a socket and listens for a connection - what I want to do
> is, if the socket has been successfully opened and the system is
> waiting for a connection, to turn the button green.
>
> The problem I'm having is when the button is clicked, the color never
> changes and the application "locks up" until the remote end connects
> and disconnects. Where can I put the button configuration statement so
> that it will turn green to indicate the socket was opened successfully?
You need to give some time to the GUI so it can draw. A minimal solution
is to call root.update_idletasks() after you set the button to green. If
you want the GUI to be responsive you have to run the socket in a
separate thread; this recipe may give you some help though it may be
more complex than you need:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965
Kent
More information about the Python-list
mailing list