如何让Python在几秒钟内自动关闭消息框?

时间:2016-04-06 03:25:21

标签: python

我已经知道如何通过Python创建一个Messagebox:

import ctypes

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

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

有没有任何方法可以实现它?

Psuedo代码:

def AutoCloseMessageBoxW(text, title, close_until_seconds)

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

但我找不到任何方法可以通过Python实现它。

1 个答案:

答案 0 :(得分:-1)

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)