简体   繁体   中英

Forcing Tkinter window to stay on top of fullscreen - Windows 10

I have a Tkinter window that I need to stay on top of everything else - including fullscreen windows.

Things I have tried:

root.attributes('-topmost', True) before mainloop - doesn't work

self.root.wm_attributes("-topmost", True) inside the class - doesn't work

root.overrideredirect(True) before mainloop - works on Linux only

root.lift() before mainloop - doesn't work

And finally, I set root.lift() to be called repetitively:

class TestingGUI:
    def __init__(self, root):
        self.root = root
        self.EnsureTop()

    def EnsureTop(self):
        root.lift()
        root.after(5000, self.EnsureTop)`

This works in the sense that it successfully raises the window over any other windows I've manually toggled to be 'always on top', using eg Dexpot, but crucially it doesn't work for fullscreen applications.

Specifically, I need this to be shown over games, as it's an in-game music player. I'm fine with solutions that require some command to be used repetitively to ensure the window is called to the top again.

As TessellatingHeckler pointed out in the comments, it's not possible to ensure a window stays on top of another fullscreen one. I solved this by combining a looping root.lift() and asking my users to run their applications in a borderless window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM