How do I clear the code of a = Label() ?
how do I clear the text of this label when using .place() function a = Label() ?
l = IntVar()
t = IntVar()
a = StringVar()
def speed():
global a
length= l.get()
time = t.get()
answer = length/time
a = Label(frame, text=answer, font="Times 13 bold", bg="Black", fg="WHITE" ).place(x = 100 , y = 160)
def clear():
'''This function is not clearing label of where I am displaying the answer in a = Label '''
l.set('')
t.set('')
#a.set('')<---NOT WORKING
#a.delete(0,'END')<----NOT WORKING
#a.destroty()<----NOT WORKING
#a.configure(text="")<---NOT WORKING
ll = Entry(frame, width=30, textvariable=l , border=5).place(x=150 , y=90)
le = Label(frame, text="Enter Length :" , font="Times 16 bold" , bg="WHITE", fg="Black" ).place(x=10 , y = 88 )
tt = Entry(frame, width=30, textvariable=t , border=5).place(x=150 , y=130)
ti = Label(frame, text="Enter Time :" ,font="Times 16 bold" , bg="WHITE", fg="Black" ).place(x=10 , y = 128 )
ans = Label(frame, text="Speed = " , font="Times 16 bold", bg="WHITE", fg="Black" ).place(x = 10 , y = 160)
spd = Button(frame, text="Calculate Speed", width=20, command=speed , bg="Black", fg="WHITE" , border = 4 ).place(x=30 , y = 190 )
cl = Button(frame, text="Clear Text", width=20, command=clear , bg="Black", fg="WHITE" , border = 4 ).place(x=200 , y = 190 )
The issue is that since you have used
.place
with the object definition of theLabel
/Entry
objects, the return value will beNone
whereas,
This is True for all layout managers -
place
,grid
andpack
Moreover, you also need to assign a
textvaribale
to yourLabel
to be able to clear them (thanks @CoolCloud)If you do not wish to add a textvariable, then simply use
.config
method ofLabel
.