I have an script that create numbers randomly, between 5 and 55, in a infinite loop. My goal is to show a message box when the number 55 is created. I have try easygui, tkinter, ctypes,... and I have been able to create the message box, but when this box appears the loop stops and it doesn't continue untill the user clicks de OK button. Is there a way to show a message box without stopping the script?
I have been looking for information in forums but I haven't found someone with this problem, so I hope someone can help me.
This is the part of the code with the loop:
def contador():
for x in range(1):
aleatorio = random.randint(1,11)*5
if aleatorio ==55:
estado = "Red"
ctypes.windll.user32.MessageBoxW(0, u"Error", u"Error", 0)
elif aleatorio >=30:
estado = "Red"
else:
estado = "Green"
global t
t = threading.Timer(15.0, contador)
t.start()
t = threading.Timer(15.0, contador)
t.start()
messageboxes in most cases (tkinter, gtk, winapi) are modal windows. You can create your own dialog or you can use threads.
import random
from Tkinter import Tk
def show_error(text):
top = Toplevel(root)
Label(top, text=text).pack()
Button(top, text="OK", command=top.destroy).pack(pady=5)
def contador():
for x in range(100):
aleatorio = random.randint(1,11)*5
if aleatorio == 55:
estado = "Red"
show_error('Some error occurred: %s' % x)
elif aleatorio >=30:
estado = "Red"
else:
estado = "Green"
contador()
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.