tkinter 多线程计时器、Label、Button
import tkinter as tk
from threading import Thread, Event
hour = 0
class ControlThread(Thread):
def __init__(self):
self._stop_event = Event()
Thread.__init__(self)
def run(self):
f1()
def terminate(self):
self._stop_event.set()
def stopped(self):
return self._stop_event.is_set()
def f1():
def count():
global hour
global x
hour += 1
hour %= 24
label_hour.config(text=str(hour))
x = label_hour.after(3600, count)
count()
def run():
global t1
t1 = ControlThread()
t1.start()
def stop():
global t1
label_hour.after_cancel(x)
t1.terminate()
root = tk.Tk()
root.title("time")
label_time = tk.Label(root, text="时刻(h)")
label_time.grid(row=0, column=0, columnspan=3)
label_hour = tk.Label(root, bg="lightblue"<