简体   繁体   English

强制Tkinter窗口保持在全屏幕的顶部 - Windows 10

[英]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. 我有一个Tkinter窗口,我需要保持其他一切 - 包括全屏窗口。

Things I have tried: 我尝试过的事情:

root.attributes('-topmost', True) before mainloop - doesn't work root.attributes('-topmost', True) - 不起作用

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

root.overrideredirect(True) before mainloop - works on Linux only root.overrideredirect(True)之前的root.overrideredirect(True) - 仅适用于Linux

root.lift() before mainloop - doesn't work root.lift()之前的root.lift() - 不起作用

And finally, I set root.lift() to be called repetitively: 最后,我设置root.lift()重复调用:

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. 这是因为它成功地将窗口提升到任何其他窗口,我手动切换为“始终在顶部”,使用例如Dexpot,但至关重要的是它不适用于全屏应用程序。

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. 正如TessellatingHeckler在评论中指出的那样,不可能确保窗口保持在另一个全屏幕之上。 I solved this by combining a looping root.lift() and asking my users to run their applications in a borderless window. 我通过组合循环root.lift()并要求我的用户在无边框窗口中运行他们的应用程序来解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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