【发布时间】:2016-04-25 17:56:29
【问题描述】:
我是 Python 新手,对 tkinter 更是如此,因此我决定尝试为 Tkinter 的无限循环创建一个开始和停止按钮。不幸的是,一旦我点击开始,它就不允许我点击停止。开始按钮保持缩进,我认为这是因为它触发的功能仍在运行。我怎样才能让这个第二个按钮停止代码?
import tkinter
def loop():
global stop
stop = False
while True:
if stop == True:
break
#The repeating code
def start():
loop()
def stop():
global stop
stop = True
window = tkinter.Tk()
window.title("Loop")
startButton = tkinter.Button(window, text = "Start", command = start)
stopButton = tkinter.Button(window, text = "Pause", command = stop)
startButton.pack()
【问题讨论】: