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

boB Stepp robertvstepp at gmail.com
Mon Apr 20 05:34:43 CEST 2015


I am not certain that my terminology is correct in the subject line.
Let me explain my issue.

Scenario A:
1) I start out inside a commercial software environment (Abbreviated
CSA henceforth).
2) I initiate a script in the CSA's scripting language.
3) This script calls an external Python script.com
4) This Python script generates a Tkinter window, populating it with
information from the CSA.
5) Control will not pass back to the CSA until the Tkinter window is
closed. Because of this, none of the CSA's tools can be used until the
Tkinter window is closed.

Scenario B:
1) I start out inside the CSA.
2) I initiate a script in the CSA's scripting language.
3) This script calls an external Python script in a new thread.
4) This Python script generates a Tkinter window, populating it with
information from the CSA.
5) Control returns to the CSA while the Tkinter window is populating
itself. The CSA's tools can be used while the Tkinter window remains
open displaying its information.

My users want scenario B to occur. This way they can refer to the
Tkinter window's info and make changes to their plan based on this
info. However! Once they make their changes they will want to rerun
the same Python script. This would then result in TWO Tkinter windows
being open, one displaying the old info, the new one with the
post-changes info. This is not acceptable.

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 need to be able to identify the existence of such a window without
causing anything to happen to the CSA's normally open windows. And
then close the particular window I need closed -- IF it is even open.
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.

Thanks!

-- 
boB


More information about the Tutor mailing list