これは私の最初のpythonプログラムです。私はtorricelliのdraintime電卓を作成しようとしていますが、 'clear result'ボタンは機能しません。計算結果をクリアしたい。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)
はあなたのすべてをありがとう!私は可能な限り、グローバル変数を使用しないよう助言するものの