【发布时间】:2018-09-06 22:10:19
【问题描述】:
以下代码将显示一个小的 Tkinter 用户界面,但是我的按钮不会触发名为 copy_loop 的循环。我已经尝试了几个小时,但我无法弄清楚如何解决这个问题。任何帮助将不胜感激。
import tkinter as tk
import threading
class App():
def __init__(self, master):
self.isrunning = False
self.button1 = tk.Button(main, text='start')
self.button1.bind = ("<Button-1>", self.startrunning)
self.button1.pack()
self.button2 = tk.Button(main, text='stop')
self.button2.bind = ("<Button-1>", self.stoprunning)
self.button2.pack()
def startrunning(self, event):
self.isrunning = True
t = threading.Thread(target=self.copy_loop)
t.start()
def stoprunning(self, event):
self.isrunning = False
def copy_loop(self):
while self.isrunning:
print("Running...")
main = tk.Tk()
app = App(main)
main.mainloop()
【问题讨论】:
标签: python tkinter python-3.7