I have a non-GUI program that sometimes needs to display a dialog to user. The problem is that my program runs in an infinite loop and when I show a dialog in this loop the execution of program halts until the dialog is dismissed and this is not wanted because my program loop is a background service that must be responsive all time. So I tried running the dialog showing code in another thread but it doesn't work properly: The dialog is shown only one time/the first time and subsequent calls show nothing.
How can I solve this problem?
This is a sample code for you to test the situation:
import tkinter
import tkinter.messagebox
import threading
import time
def messageBox():
root=tkinter.Tk()
root.withdraw()
tkinter.messagebox.showinfo('dialog', 'test')
root.destroy()
while True:
threading.Thread(target=messageBox).start()
time.sleep(3)
I use Python 3.3.4 on Windows XP
我的建议是使对话框成为单独的脚本,并使用子过程模块在单独的过程中显示对话框。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.