简体   繁体   English

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

[英]Display tkMessageBox above all other running applications

I have a python program that, at a certain point when conditions are met, displays a tkMessageBox. 我有一个python程序,该程序在满足条件的某个时刻显示tkMessageBox。

The intended use of this program is to start it, minimize it and then after a certain time get the alert. 该程序的预期用途是启动它,将其最小化,然后在一定时间后得到警报。 But when I use tkMessageBox, the message stays 'hidden' behind all the other applications that I have opened (Firefox etc.). 但是,当我使用tkMessageBox时,该消息“隐藏”在我打开的所有其他应用程序(Firefox等)之后。

Is there a way to put the messagebox in focus/push it above all the other applications? 有没有一种方法可以将消息框置于焦点/将其置于所有其他应用程序之上?

Thank you. 谢谢。

Edit: I'm using Lubuntu and Python 2.7 编辑:我正在使用Lubuntu和Python 2.7

Well, you can make tkMessageBox raise above all other windows only along side with root: 好吧,您可以使tkMessageBox仅在与root并排的所有其他窗口上方引发:

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

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

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