I am creating a Reset button of a GUI by using the Tkinter. My purpose is that reset all values of labels to 0 or disappear.
To reset value of labels, I defined the labels as global variable.
labelP = None
labelV = None
labelH = None
labelT = None
Main function:
def predict():
global labelP
global labelV
global labelH
global labelT
...
labelP = Label(mainframe, text = np.array(A[1,0]), width=5, font = 'Arial 10 bold').grid(column=2, row=5, sticky=W)
labelV = Label(mainframe, text = np.array(A[1,1]), width=5, font = 'Arial 10 bold').grid(column=2, row=6, sticky=W)
labelH = Label(mainframe, text = np.array(A[1,2]), width=5, font = 'Arial 10 bold').grid(column=2, row=7, sticky=W)
labelT = Label(mainframe, text = np.array(A[1,3]), width=5, font = 'Arial 10 bold').grid(column=2, row=8, sticky=W)
...
reset function:
def reset():
global labelP
global labelV
global labelH
global labelT
labelP.delete()
labelV.delete()
labelH.delete()
labelT.delete()
Reset button:
btn2 = Button(mainframe, text="Reset", command = reset).grid(column=1, row=9, sticky=W)
Although I also tried labelP.config()
, labelP.set("")
, labelP.destroy()
but I always get the error:
AttributeError: 'NoneType' object has no attribute ...
What should I define for the global variables?
Thank you This is my code: https://gist.github.com/TonyS0n/8ee8db392196a405c2ef27ac44df3059