How do I clear the code of 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 the Label
/Entry
objects, the return value will be None
x = Label(<configurable_options>).place(...) # x is None
whereas,
x = Label(<configurable_options>) # defines x as a Label object
x.place(...) # places x at your desired location
This is True for all layout managers - place
, grid
and pack
Moreover, you also need to assign a textvaribale
to your Label
to be able to clear them (thanks @CoolCloud)
l = StringVar()
l1 = Label(..., textvariable=l)
If you do not wish to add a textvariable, then simply use .config
method of Label
.
l1.config(text='')