這是我的第一個python程序。我正在嘗試創建torricelli的排空時間計算器,但「清除結果」按鈕不起作用。我想要它清除計算結果。Python Tkinter GUI:'清除結果'按鈕不起作用
我得到這個錯誤:
Traceback (most recent call last):
File "C:\Users\David \Desktop File\GUI_DrainTime_Calculator.py", line 83, in clear
drain_label.destroy()
NameError: name 'drain_label' is not defined
請幫我弄清楚爲什麼這個NameError仍然存在。 這是罪魁禍首:
drain_label = Label(
WIN,
font=('Helvetica', 8, 'bold'),
text="The time it takes for the liquid to drain is: %.0f hour, %.0f minutes, and %.0f seconds." % (hr, Min, sec)).pack(side=BOTTOM)
def clear():
drain_label.destroy()
Clearbtn = Button(WIN, text="Clear Results", font('Helvetica',7,'bold'), fg='black',command=clear)
Clearbtn.configure(background='grey')
Clearbtn.pack(side=TOP,pady=5)
謝謝大家!