pythonpython-3.xtkinterpython-3.6easygui

Python 3.6 open a message box using Tkinter and continue with the script


I have a script that runs a program and then begins a while True loop. I want to open a message box using easyGUI (that simplifies tkinter, so essentially, I want to open a message box using tkinter) and then enter into the while loop. When the message box is dismissed, I want to break from the loop and then kill the program.

My question is, how do I achieve this?

Current script (section of):

import subprocess, easygui
from time import sleep    

f = open("file.txt", "w")

notOpen = True

while True:
    if notOpen == True:
        subprocess.Popen("program.exe", shell=True, stdout=open(os.devnull, 'wb'))
        easygui.msgbox("\nRunning!", "FSRP engine")
        notOpen = False
    f.write("1=")
    f.flush()
    sleep(5)
    f.write("2=")
    f.flush()
    sleep(5)
    f.write("3")
    f.flush()
    sleep(5)

Solution

  • You just need to add None sector.

    So your code would be:

    import subprocess, easygui
    from time import sleep    
    
    f = open("file.txt", "w")
    
    notOpen = True
    
    while True:
        if notOpen == True:
            subprocess.Popen("program.exe", shell=True, stdout=open(os.devnull, 'wb'))
            if easygui.msgbox("\nRunning!", "FSRP engine") == 'OK':
                notOpen = False
            else:
                break
        f.write("1=")
        f.flush()
        sleep(5)
        f.write("2=")
        f.flush()
        sleep(5)
        f.write("3")
        f.flush()
        sleep(5)
    

    Or:

    import subprocess, easygui
    from time import sleep    
    
    f = open("file.txt", "w")
    
    notOpen = True
    
    while True:
        if notOpen == True:
            subprocess.Popen("program.exe", shell=True, stdout=open(os.devnull, 'wb'))
            if easygui.msgbox("\nRunning!", "FSRP engine") == 'OK':
                notOpen = False
            else:
                exit
        f.write("1=")
        f.flush()
        sleep(5)
        f.write("2=")
        f.flush()
        sleep(5)
        f.write("3")
        f.flush()
        sleep(5)