如何使用Python使messagebox在几秒钟内自动关闭?

2024-05-18 10:09:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经知道如何用Python制作Messagebox:

import ctypes

ctypes.windll.user32.MessageBoxW(0, 'test', "Reminding", 0)

但是,我希望它在出现后几秒钟内自动关闭。在

有什么方法可以实现吗?在

Psuedo代码:

^{pr2}$

我已经找到了很多方法来实现这一点,通过其他语言,比如C#和Java。在

但是我找不到任何用Python实现它的方法。在


Tags: 方法代码testimport语言javactypes几秒钟
1条回答
网友
1楼 · 发布于 2024-05-18 10:09:17
import ctypes
import threading
import time
#ctypes.windll.user32.MessageBoxA(0, 'test', "Reminding", 0)

def worker(title,close_until_seconds):
    time.sleep(close_until_seconds)
    wd=ctypes.windll.user32.FindWindowA(0,title)
    ctypes.windll.user32.SendMessageA(wd,0x0010,0,0)
    return

def AutoCloseMessageBoxW(text, title, close_until_seconds):
    t = threading.Thread(target=worker,args=(title,close_until_seconds))
    t.start()
    ctypes.windll.user32.MessageBoxA(0, text, title, 0)


AutoCloseMessageBoxW('112','TEST_CLOSE',3)

相关问题 更多 >