79602178

Date: 2025-05-01 16:17:54
Score: 2
Natty:
Report link

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.

enter image description here

When 30 is the aleatorio. Green will appear in the MessageBoxW.

enter image description here

Reasons:
  • Blacklisted phrase (1): Is there a way
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: Adios Gringo