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

Steven D'Aprano steve at pearwood.info
Fri Apr 24 15:41:56 CEST 2015


Coming in late to this conversation... 


On Sun, Apr 19, 2015 at 10:34:43PM -0500, boB Stepp wrote:

> 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.

I think one way of doing this is by making the Python script a daemon 
that runs in the background. That at least will solve the problem from 
Scenario A that the CSA becomes unresponsive while the Tkinter window is 
open: as far as the CSA is concerned, the process it launched has ended.

Three follow-up problems then occur:

- Can daemons run as graphical applications?

- Once the daemon is running, how does the CSA communicate with it?

- How do we make sure that the daemon closes down safely when the 
  CSA quits?


I don't know the answers to these.

Ben Finney maintains a Python daemon library. If Ben is around, he may 
be able to shed some further light onto this question, and answer 
whether a daemon is suitable. Perhaps even give some sample code.



-- 
Steve


More information about the Tutor mailing list