[Idle-dev] IDLE getpass?

Tal Einat taleinat at gmail.com
Fri Aug 17 04:18:10 CEST 2007


On 8/16/07, Douglas S. Blank <dblank at brynmawr.edu> wrote:
> Ok, I can't find anything to fix this. I've tried combinations of lower,
> lift, deiconify, iconify, update, overridedirect, ... but nothing I do
> can get a new Tk window to appear on top of IDLE.
>
> This is very confusing for new students (and experts). I'll do whatever
> is necessary even it requires plugin or whatever. Can I lower IDLE?
>
> Any ideas?
>
> -Doug
>
> Here's some code to help anyone see the problem:
>
> # in IDLE on Windows XP:
> import Tkinter
> tl = Tkinter.Toplevel()
> tl.update()
> tl.raise()
> ...
>
> I can't get the tl window to appear on top of IDLE.
>

Well, I ran into trouble at first too when trying to do this. In the
end I realized that deiconify(), tkraise() and focus() need to be
called once the Tk object's mainloop is already running. And that they
must be called from the same thread that the mainloop is running in,
so threads must be avoided.

This seems to do the trick:

def raised():
       top = Tk()
       text = Text(top)
       text.pack(expand=True)
       top.after(50, top.deiconify)
       top.after(50, top.tkraise)
       top.after(50, text.focus)
       top.mainloop()


Of course, using 'after' like this is an ugly hack. If the call to
mainloop is delayed somehow, then the window will not be raised
(that's why I used a 50 millisecond delay). I played around with
cleaner possibilities but ran into some difficulties... It's too late
at night, I'll give it another look tomorrow.

- Tal


More information about the IDLE-dev mailing list