[Tkinter-discuss] Persuading after_idle callback to only get called when the window is mapped

Geoff Bache geoff.bache at gmail.com
Mon Jan 11 20:19:19 CET 2010


On Mon, Jan 11, 2010 at 8:16 PM, Geoff Bache <geoff.bache at gmail.com> wrote:
> Hi Geoff,
>
> On Sat, 9 Jan 2010 23:06:17 +0100
> Geoff Bache <geoff.bache at gmail.com> wrote:
>
>> Hi all,
>>
>> I'm trying to add an idle callback via the after_idle method, called
>> before mainloop. The problem is that I want to interact with the GUI
>> widgets
>> (doing very basic GUI testing) from this callback so I need the window
>> to be mapped by the window manager. But my callback gets called before
>> this has happened. If I then just call after_idle again from it the
>> window never appears at all.
>>
>> Is there a nice way of waiting until there is a window to play with
>> before calling it? I can hardcode a delay by calling "after" instead,
>> and
>> this works but is obviously not ideal.
>>
>
> Have you tried wait_visibility() ?
> If this doesn't work for you, maybe you could bind a callback to <Map>
> events.

I have got something that seems to work now, which is to create a
thread, call wait_visibility in it
and then add the idle handler, and then call update_idletasks at the
beginning of the idle
handler. Feels to me like all that fuss shouldn't really be necessary,
but there we are. If anyone
knows of a simpler way I'd be interested to hear what it is.

Thanks,
Geoff


More information about the Tkinter-discuss mailing list