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?
Yes. You can do by changing Timer
to 0.15
instead of 15.0
Snippet(re-modified)
import random
import ctypes
import threading
# Global variable to hold the state
estado = ""
def contador():
global estado # Declare estado as global to modify it
aleatorio = random.randint(1, 11) * 5
print(aleatorio)
if aleatorio == 55:
estado = "Red"
ctypes.windll.user32.MessageBoxW(0, estado, u"Error", 0)
elif aleatorio == 30:
ctypes.windll.user32.MessageBoxW(0, 'Green', u"Error", 0)
# Restart the timer
t = threading.Timer(0.15, contador)
t.start()
contador()
Screenshot:
When 55 is the aleatorio
. Red will appear in the MessageBoxW.
When 30 is the aleatorio
. Green will appear in the MessageBoxW.