Command Line drive Tk window

annagel andrew.nagel at gmail.com
Sat Dec 3 14:44:31 EST 2005


I have been working to build a media toolkit that uses pygame to modify
image and sound data for the user.  I have all of this working fine.
The one thing I am working on now is adding a pop-up view for the image
data as well as some pop-ups for file selection and color picking.  I
am having problems with the first part of this which I think will carry
through to the file/color pickers but all of that is secondary anyway
so not too big a deal.

Basically the module is set up so after importing it must be
initialized.  This initializes a bunch of pygame stuff and also starts
a thread to watch for user events on its windows.  I just create a Pk
instance and withdraw it (this is ok because this thread is run as
daemon so the program won't be stalled from exiting by a window they
can't see to close).  Then when the user wants to view one of their
images in a window they call a function in the object which converts
the image to a PIL image and imports it to a Toplevel Pk window.  The
problem is that this window does not become visible.  I did some
investigation and found that if I did not withdraw my root window I
could get the Toplevel to show by clicking the root window.  What I
think what is actually going on here is that the Tk mainloop is only
looking for user events generated by the gui itself so when I try to do
something from the comand line the mainloop is not looking for the
event.

Does anyone know of a way I can overcome this problem.  I have tried
creating a second loop that just keeps hitting the main window by
calling update, this does not work the update stalls until I click with
window just like creation of the toplevel window.  Finally I have also
tried cyclicly adding an after_idle call to the window so it will keep
calling some function when it goes to idle figuing I could keep the
main loop alive perhaps in this way.  This prevented the main window
from apearing at all and so this is not a good option.

Any thought would be apreciated,
Andrew




More information about the Python-list mailing list