Python 3.6 使用 Tkinter 打开消息框并继续执行脚本

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

我有一个运行程序然后开始 while True 循环的脚本。我想使用 easyGUI 打开一个消息框(它简化了 tkinter,所以本质上,我想使用 tkinter 打开一个消息框)然后进入 while 循环。当消息框关闭时,我想 break 从循环中退出然后终止程序。

我的问题是,我该如何实现?

当前脚本(部分):

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)

您只需添加 None 个扇区。

因此您的代码将是:

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)

或者:

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)