Python- Displaying a message box that can be closed in the code (no user intervention)

一个人想着一个人 提交于 2019-12-02 01:48:04

To forcibly remove on timeout a message box created with easygui you could use .after() method:

from Tkinter    import Tk
from contextlib import contextmanager

@contextmanager
def tk(timeout=5):
    root = Tk() # default root
    root.withdraw() # remove from the screen

    # destroy all widgets in `timeout` seconds
    func_id = root.after(int(1000*timeout), root.quit)
    try:
        yield root
    finally: # cleanup
        root.after_cancel(func_id) # cancel callback
        root.destroy()

Example

import easygui

with tk(timeout=1.5):
    easygui.msgbox('message') # it blocks for at most `timeout` seconds

easygui is not very suitable for your use case. Consider unittestgui.py or Jenkins.

If you have started to create a GUI, you should be able to use the textbox() function. A text box could be used as a place for your status messages, rather than making a separate dialog window appear.

I got the following description of textbox() here:

textbox(msg='', title=' ', text='', codebox=0)

Display some text in a proportional font with line wrapping at word breaks. This function is suitable for displaying general written text. The text parameter should be a string, or a list or tuple of lines to be displayed in the textbox.

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