在所有其他正在运行的应用程序上方显示tkMessageBox

时间:2016-06-03 15:06:04

标签: python python-2.7 tkinter

我有一个python程序,在满足条件的某个时刻,显示一个tkMessageBox。

此程序的预期用途是启动它,将其最小化,然后在一定时间后获取警报。但是当我使用tkMessageBox时,消息会“隐藏”在我打开的所有其他应用程序后面(Firefox等)。

有没有办法将消息框置于焦点/将其推到所有其他应用程序之上?

谢谢。

编辑:我正在使用Lubuntu和Python 2.7

1 个答案:

答案 0 :(得分:0)

好吧,你可以让tkMessageBox只提升到所有其他窗口的上方:

from Tkinter import Tk              # For this example we only need Tk
from tkMessageBox import showinfo

root = Tk()         # We need a main window

def showMessage():
    root.attributes('-topmost', 1)              # Raising root above all other windows
    root.attributes('-topmost', 0)              
    showinfo("Title", "Sample text Message")    # Actual message

root.after(3000, showMessage)       # Starting function 'showMessage' in 3000 milliseconds (3 seconds)
root.mainloop()                     # Starting mainloop