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

boB Stepp robertvstepp at gmail.com
Fri Apr 24 19:23:19 CEST 2015


On Fri, Apr 24, 2015 at 8:41 AM, Steven D'Aprano <steve at pearwood.info> wrote:

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

This part sounds promising.

> Three follow-up problems then occur:
>
> - Can daemons run as graphical applications?
>
> - Once the daemon is running, how does the CSA communicate with it?

I'd be extremely interested if this is possible! My biggest struggles
are exchanging information between the CSA and other programs external
to it. And it is much harder going in one direction than the other.
Liberal use of temp files seems to be the most reliable means of
exchanging information, though some exploitation of the CSA's global
variables is possible, though this is usually a last ditch effort when
nothing else seems to work.

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

I'll keep my fingers crossed!

-- 
boB


More information about the Tutor mailing list