Discussion:
Lift Tkinter window on Win32
Alex
2001-09-19 13:29:28 UTC
Permalink
I have not found the solution yet, but for those of you, who have
similar problem, it seems that the culprit is the following:

(quote form http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q227043)

"If you design an application for Windows 98 and/or Windows 2000 with
the assumption that you can always take over the active window, your
application may fail. If your application tries to take over the
foreground under restricted conditions, your application flashes in
the user's taskbar. Your application can take over the foreground
under one of the following conditions ..."

Indeed, SetForegroundWindow causes the target window to flash on the
taskbar...

Alex
Alex
2001-09-18 15:25:04 UTC
Permalink
Hi, everybody!

I have encountered a peculiar problem while trying to do as simple thing as
getting a Tkinter window to be the foreground window.

I'm running Python 1.5.2 on Windows 98 with Tcl/Tk 8.0.5

I started with an obvious wnd.lift() (or tkraise), which does not work (!).
It only raises the wnd over the other Tkinter windows, not other application
windows.
Any ideas why?

Frustrated, I decided to play dirty and call
win32gui.SetForegroundWindow( atoi(wnd.frame()) )
which didnt work either.

Probing further, I wrote a piece of C code, which did SetForegroundWindow on
the Tkinter window in question - IT WORKS!
However, if I compile the very same piece of C code into Python extension module
and call it from within Python code - IT DOESN'T WORK!

Can anyone please shed some light on this.
TIA,
Alex
Joonas Paalasmaa
2001-09-18 15:41:31 UTC
Permalink
Post by Alex
Hi, everybody!
I have encountered a peculiar problem while trying to do as simple thing as
getting a Tkinter window to be the foreground window.
I'm running Python 1.5.2 on Windows 98 with Tcl/Tk 8.0.5
I started with an obvious wnd.lift() (or tkraise), which does not work (!).
It only raises the wnd over the other Tkinter windows, not other application
windows.
Any ideas why?
Frustrated, I decided to play dirty and call
win32gui.SetForegroundWindow( atoi(wnd.frame()) )
which didnt work either.
Probing further, I wrote a piece of C code, which did SetForegroundWindow on
the Tkinter window in question - IT WORKS!
However, if I compile the very same piece of C code into Python extension module
and call it from within Python code - IT DOESN'T WORK!
Can anyone please shed some light on this.
I am not sure about this, but this might work

self.master.iconify()
self.master.update()
self.master.deiconify()
Alex
2001-09-20 11:06:35 UTC
Permalink
Post by Alex
I have not found the solution yet, but for those of you, who have
(quote form http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;Q227043)
"If you design an application for Windows 98 and/or Windows 2000 with
the assumption that you can always take over the active window, your
application may fail. If your application tries to take over the
foreground under restricted conditions, your application flashes in
the user's taskbar. Your application can take over the foreground
under one of the following conditions ..."
Indeed, SetForegroundWindow causes the target window to flash on the
taskbar...
Alex
Seems like I'm monopolyzing this thread but I thought that after two
days
of trying to figure out the matter, there may be at least one poor
soul interested in what I have come up with.

Since I still have no success in calling window.lift(), I've gone with
:

hwnd = string.atoi( window.frame(), 0 )
win32gui.SetForegroundWindow( hwnd )

On Win98 (and reportedly on W2k), however, the nasty foreground window
restriction messes up things. To circumvent that, I ran the following
C code:

#ifndef SPI_SETFOREGROUNDLOCKTIMEOUT
// older version of winuser.h doesnt have it defined
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
#endif

SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0,
SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);

which apparently switches off some sort of
foreground-setting-lock-timeout-thing

Hope it helps someone out there.
BTW, I would still be interested in solution/explanation of the
.lift() problem.

Alex
Guido van Rossum
2001-10-09 14:00:13 UTC
Permalink
Alex, have you tried to bring this up in a Tcl/Tk newsgroup? That's
where the solution ultimately has to come from.

--Guido van Rossum (home page: http://www.python.org/~guido/)

Loading...