简体   繁体   English

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

[英]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. 我有一个运行程序的脚本,然后启动while True循环。 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. 我想使用easyGUI(简化tkinter,因此从本质上讲,我想使用tkinter打开消息框)打开消息框,然后进入while循环。 When the message box is dismissed, I want to break from the loop and then kill the program. 当消息框被驳回,我想break由循环,然后杀程序。

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)

You just need to add None sector. 您只需要添加None扇区。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM