Make a tkinter window appear over all other windows

白昼怎懂夜的黑 提交于 2019-12-30 05:23:36

问题


#!/usr/bin/env python
# Display window with toDisplayText and timeOut of the window.

from Tkinter import *

def showNotification(notificationTimeout, textToDisplay):

    ## Create main window
    root = Tk()
    Button(root, text=textToDisplay, activebackground="white", bg="white", command=lambda: root.destroy()).pack(side=LEFT)

    root.update_idletasks()
    # Remove window decorations
    root.overrideredirect(1)

    timeOut = int(notificationTimeout*1000) # Convert to ms from s

    ## Run appliction
    root.after(timeOut,root.destroy)
    root.mainloop()

The above code creates a notification, with a timout. However on windows - the notification does not automatically pop up above all other present windows automatically. One has to click on the kill button (the text), and focus it the first time, after which the root window will be displayed above all other windows.

Is there a way to make the notification automatically appear above all other windows - on windows?

It seems to work on linux just fine (ubuntu 9.10).


回答1:


According to this message you should be able to add the following after root.overridedirect(1). A quick test here suggests it should work for you.

root.wm_attributes("-topmost", 1)


来源:https://stackoverflow.com/questions/1918752/make-a-tkinter-window-appear-over-all-other-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!