我的計數器不會停止。當我第二次啓動時,我希望它繼續計數,而不是重新啓動。Tkinter程序的行爲不像我認爲的那樣
from tkinter import *
master = Tk()
Counter_Activation_Variable=3
def start():
Counts=0
Counter_Activation_Variable=0
button.configure(text = "Stop", command=stop)
while Counter_Activation_Variable == 0:
Counts = Counts+1
Textbox.delete(1.0, END)
Textbox.insert(END,(Counts))
master.update()
def stop():
Counter_Activation_Variable=5
button.configure(text = "Start", command=start)
master.update()
button = Button(master, text="Start",command=start, bg="grey")
button.pack(side='bottom', fill='none', expand=False, padx=4, pady=4)
master.title("Stopwatch")
Textbox = Text(master, height=1, width=175)
Textbox.pack(side='top', fill='none', expand=False, padx=4, pady=4)
master.mainloop()
描述性變量和方法名稱真的會在這種情況下有所幫助:) –
你是什麼意思對不起,如果它明顯,但即時通訊新編碼大部分這個我只是從其他網站一起凝結和理解 – PLP123
我可以弄清楚你的代碼函數,但使用諸如「timer_status」而不是「a」或「seconds」而不是「x」的描述性變量名稱,確實使編程變得光榮。這是一個很好的提示,因爲你是新的:) –