123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import timeimport tkinter as tkimport randomwindow = tk.Tk()var1 = tk.StringVar()text = tk.Label(window, textvariable=var1)text.grid(row=0, column=1)going = Trueis_run = Falsedef getnum(var1): global going a = random.randint(0, 100000) str_a=str(a) var1.set(str_a) if going: window.after(100, getnum, var1) else: going = True returndef start(var1): global is_run if is_run: return is_run = True getnum(var1)def stop(): global going, is_run if is_run: going = False is_run = Falsebut = tk.Button(window, text="开始", command=lambda: start(var1))but.grid(row=1, column=1)but2 = tk.Button(window, text="结束", command=stop)but2.grid(row=1, column=2)window.mainloop()