Waiting for Connection

D

D

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?
Thanks!
 
K

Kent Johnson

D said:
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
 
D

D

Thanks Kent! update_idletasks() does exactly what I needed, which as
you mentioned was just to give it enough time to reconfigure the
button.

Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,285
Messages
2,571,416
Members
48,107
Latest member
AmeliaAmad

Latest Threads

Top