Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tk window and Windows' user32 SetWindowPos interactions?

122 views
Skip to first unread message

George Furbish

unread,
May 27, 2021, 5:05:22 PM5/27/21
to
I'm trying to use SetWindowPos (https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos) to interact with a Tk window, but nothing seems to happen in spite of SetWindowPos returning a non-zero value, indicating the action should have been successful.

Does Tk do something magical that interacts poorly with SetWindowPos?

I've also created a StackOverflow question for this issue.
https://stackoverflow.com/questions/67713248/forcing-tkinter-window-to-render-below-everything-else-with-native-python

-George

ted brown

unread,
May 28, 2021, 1:52:43 AM5/28/21
to
In windows I often use the twapi package to set window parameters. I
tried your settings for the flags in a call to twapi::SetWindowPos and
nothing seemed to happen to the window I was trying it on.

Then I saw that you have set it to ignore the position and size
parameters. So, I changed that to allow it to move and resize, and it
would then do that.

My suggestion is that you try it without the SWP_NOSIZE and/or
SWP_NOMOVE just to see if it will then use your 0,0,400,600 parameters.
That would tell you if you are even getting the call to SetWindowPos to
work on your window at all.

At first I thought the flags were there to change the window, but then I
realized they are used to suppress some of the other required arguments
to the call. That was a surprise to me, how about you?

In twapi, one can set windows styles and that seems to have many
effects, including ones that remove the ability to move the window, and
even remove the icon from the task bar.

Internally twapi uses Get/SetWindowLongPtr to get/set styles. Perhaps
those windows calls might be something you could look into.

George Furbish

unread,
May 29, 2021, 9:19:15 AM5/29/21
to
Following this guide, I was able to do what I wanted to do by setting tkinter's parent window to another window.

1. Find the window behind the desktop:
https://www.codeproject.com/Articles/856020/Draw-Behind-Desktop-Icons-in-Windows-plus

2. Set the Tkinter root window's parent to that window using SetParent()
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setparent

However, it still renders the original Tkinter popup in addition to drawing as a child of the other window like I wanted. What's going on there and how do I fix it? Interestingly enough, using SetWindowLongPtr() on Tkinter's root window to make it a child and not a popup before calling SetParent() does not get rid of the original Tkinter popup and prevents it from drawing as a child of the other window. Backwards progress with that attempt...

George Furbish

unread,
May 29, 2021, 10:14:10 AM5/29/21
to
Drawing updates (e.g. changing the window's background color) are correctly rendered to the window painted on the new parent window (desktop) as desired, but the original window's popup remains and can be resized, repositioned, closed, etc.

George Furbish

unread,
May 29, 2021, 5:51:00 PM5/29/21
to
Looks like overrideredirect(True) solved that. Now I just have to figure out how to get the new window's 0,0 to be the screen's 0,0. The helper window I picked as a parent to render on the desktop is not in that spot, and I'm not sure how reliably it chooses its position.
0 new messages