如何在脚本运行时显示消息

时间:2014-04-03 13:53:47

标签: python python-2.7 ctypes messagebox tkmessagebox

我已经在Python中创建了一个可以运行一分钟的脚本。当我的脚本运行时,我喜欢在windows7中为用户提供一个脚本正在运行的消息框。

可能的事情是在脚本启动时显示消息,并在脚本完成时卸载此消息。

目前我使用tkMessageBox来提供一些信息。我也查看了ctypes.windll.user32.MessageBoxA,但无法找到解决方案。

1 个答案:

答案 0 :(得分:0)

我很久以前就试过这个。我知道这不是美容方式,可能Python很讨厌这样做,但它仍然适用于我。

您仍然会收到错误消息,但确实有效。也许其他人可以纠正我并以更好的方式做到这一点。这是代码:

import Tkinter
import tkMessageBox
import thread

top = Tkinter.Tk()
def hello():
    tkMessageBox.showinfo("Say Hello", "Hello World")

B1 = Tkinter.Button(top, text = "Say Hello", command = hello)
B1.pack()

thread_to_stop = thread
try:
    thread_to_stop.start_new_thread(top.mainloop,(0,))
except:
    pass

print "Python doesn't like this very much"
raw_input("You choose when to close it!")
# Do more stuff here....
top.destroy()
相关问题