Possible Win32 Tkinter bug?

Eric Brunel eric.brunel at pragmadev.com
Fri Nov 15 04:41:14 EST 2002


Tim Daneliuk wrote:
> Hmmm, this is a strange one:
> 
> I have Tkinter program which works pretty much as I want. Among the
> things it does at startup time is to first establish the main UI and
> then optionally use a tkMessageBox.showwarning() to let the user know if
> there is a problem with the contents of a config file. After the user
> presses OK, the warning disappears and only the main UI window is
> left.
> 
> Under X, this works just fine. Under Win32 the program works fine if no
> warning message box every appears. However, if a warning is displayed,
> the main UI never gets focus back after the user presses OK on the
> message box. I have to select on a completely separate Win32 window or
> the Desktop and then back to the main UI before I get focus back
> to the widget in the Tk application again.
> 
> If I had this problem in both environments I would rapidly assume it
> is my poor understanding of Tkinter that is the problem.  However,
> since it works fine in one environment and not the other, it would
> suggest several possibilities:
> 
> 1) A Tkinter/Python problem on Win32 (python 2.2.2 on Win2K SP3)
> 2) Strange Win32 semantics which I am not accommodating
> 3) Stupid coding on my part only revealed on Win32...
> 
> Has anyone seen this before?

Windows has a quite different idea on which window should get the focus 
than any other window manager on other platforms. We often encountered such 
strange behaviours.

Did you try to explicitely do a tkraise and/or focus_set on the main window 
after your message box has been shown? It may help. I also once saw that 
calling successively withdraw(), then deiconify() on the main window can 
solve such problems.

In other words: you're on Windows, so the standard way to do things is to 
hack until you get the behaviour you want... ;-)

HTH
-- 
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com



More information about the Python-list mailing list