[Tutor] How to close a Tkinter window from a different thread?

Alan Gauld alan.gauld at btinternet.com
Mon Apr 20 09:10:38 CEST 2015


On 20/04/15 04:34, boB Stepp wrote:

> So, how do I:
> 1) Check for the existence of an already open window from a previous
> running of the script?
> 2) If such a window exists, how do I close it from the new script
> execution? And, then, of course generate a new instance of the
> information window.

I would suggest forgetting about windows and think about
the processes that create them. Use the OS tools (via
the os module) to see if the first process is still running.
If so kill the process - which will in turn kill the window.

You can find the process based on its name or based on
its PID which you could store in a file somewhere
(like in /tmp?)

> I feel the solution must be in Tkinter's access to the X Window
> system, but nothing in the documentation is *clicking* with me yet.

Trying to manipulate GUIs via the windowing system should always
be a last resort, it is very hard to get right.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list