python提示对话框自动关闭,Python-显示一个可以在代码中关闭的消息框(无需用户干预)...

I am creating test scripts using Python. I need to have a message displayed to the user while the script continues to run. This is to have some status update , for eg: "Saving test results" which should not wait for the user to click "Ok". Essentially , I need to create a message that pops up and closes without the user having to do it.

Currently,I am using easygui module for adding GUI.Easygui can be used for creating such message boxes but they cannot be closed in the code and need to wait for the user to close them for the script to continue running.

Thanks in advance for your time and help.

Kavitha

解决方案

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值