【问题标题】:I want my messagebox to pop-up in the foreground我希望我的消息框在前台弹出
【发布时间】:2020-07-07 02:04:19
【问题描述】:

我希望我的消息框在我正在运行的任何应用程序的前台弹出。目前它在后台弹出。我只能通过通知声音来判断。 我尝试了顶层,但我没有工作。 我正在运行 python 3.8

import time
from tkinter import *
from tkinter import messagebox


print("Testing program")
time.sleep(5)
print("Program tested")
window=Tk()
window.withdraw()
messagebox.showinfo('Successful','Script executed successfully')
window.deiconify()
window.destroy()
window.quit()

【问题讨论】:

  • window=Tk() 之后添加window.attributes('-topmost', 1)。也无需在window.destroy() 之前调用window.deiconify()

标签: tkinter messagebox


【解决方案1】:

以下是任何需要的人的工作代码:

import time
from tkinter import *
from tkinter import messagebox


print("Testing program")
time.sleep(5)
print("Program tested")
window=Tk()
window.attributes('-topmost',1)
window.withdraw()
messagebox.showinfo('Successful','Script executed successfully')
window.deiconify()
window.attributes("-topmost", True)
window.destroy()
window.quit()

【讨论】:

    【解决方案2】:

    如果您.destroy() 窗口,那么您正在关闭它。另外,你需要使用.mainloop(),如果你.quit()它,那么它根本不会出现。

    这是您的代码。您需要使用.attributes() 并将其放在最顶部。

    代码:

    import time
    from tkinter import *
    from tkinter import messagebox
    
    
    print("Testing program")
    time.sleep(5)
    print("Program tested")
    window=Tk()
    window.withdraw()
    messagebox.showinfo('Successful','Script executed successfully')
    window.deiconify()
    window.attributes("-topmost", True)
    window.mainloop()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-19
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 2011-10-28
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      相关资源
      最近更新 更多