如何清除使用 Tkinter label().place() 函数显示的文本
How do I clear text displayed using Tkinter label().place() function
如何清除 a = Label() 的代码?
使用 .place() 函数 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 )
问题在于,由于您已将 .place
与 Label
/Entry
对象的对象定义一起使用,因此 return 值将为 None
x = Label(<configurable_options>).place(...) # x is None
然而,
x = Label(<configurable_options>) # defines x as a Label object
x.place(...) # places x at your desired location
对于所有布局管理器 - place
、grid
和 pack
,这是 True
此外,您还需要为您的Label
分配一个textvaribale
才能清除它们(感谢@CoolCloud)
l = StringVar()
l1 = Label(..., textvariable=l)
如果您不想添加文本变量,则只需使用 Label
的 .config
方法。
l1.config(text='')
如何清除 a = Label() 的代码?
使用 .place() 函数 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 )
问题在于,由于您已将 .place
与 Label
/Entry
对象的对象定义一起使用,因此 return 值将为 None
x = Label(<configurable_options>).place(...) # x is None
然而,
x = Label(<configurable_options>) # defines x as a Label object
x.place(...) # places x at your desired location
对于所有布局管理器 - place
、grid
和 pack
此外,您还需要为您的Label
分配一个textvaribale
才能清除它们(感谢@CoolCloud)
l = StringVar()
l1 = Label(..., textvariable=l)
如果您不想添加文本变量,则只需使用 Label
的 .config
方法。
l1.config(text='')