Him_Hei 2022-09-18 03:40 采纳率: 57.1%
浏览 535

Python messagebox如何做到自动关闭?

有没有知道Python的messagebox窗口怎么自动关闭呀?
比如创建了一个messagebox.showwaning("Test", message=Pass)
怎么使这个窗口如果没有操作10秒后自动关闭呢?

  • 写回答

1条回答 默认 最新

  • _GX_ 2022-09-18 03:59
    关注
    def showMessage(message, type='info', timeout=2500):
        import tkinter as tk
        from tkinter import messagebox
    
        root = tk.Tk()
        root.withdraw()
        try:
            root.after(timeout, root.destroy)
            if type == 'info':
                messagebox.showinfo('Info', message, master=root)
            elif type == 'warning':
                messagebox.showwarning('Warning', message, master=root)
            elif type == 'error':
                messagebox.showerror('Error', message, master=root)
        except:
            pass
    
    showMessage("Hello, world", timeout=5000)
    
    评论

报告相同问题?

问题事件

  • 创建了问题 9月18日

悬赏问题

  • ¥25 主成分分析中的第一第二主成分分别代表哪些参数
  • ¥15 oracle数据库查询语句问题
  • ¥15 有没有c++绘制算法的佬们吗救孩一下
  • ¥15 android 蓝牙闪退
  • ¥15 绝缘子污秽comsol仿真参数
  • ¥15 Fatal error in Process MEMORY
  • ¥15 labelme生成的json有乱码?
  • ¥30 arduino vector defined in discarded section `.text' of wiring.c.o (symbol from plugin)
  • ¥20 如何训练大模型在复杂因素组成的系统中求得最优解
  • ¥15 关于#r语言#的问题:在进行倾向性评分匹配时,使用“match it"包提示”错误于eval(family$initialize): y值必需满足0 <= y <= 1“请问在进行PSM时