0
我想做一个函数,将文本添加到文本框,如果它后面的变量是空的。我试图做到这一点使用.LEN()函数,但我得到一个找到一个字符串的长度
AttributeError: 'StringVar' object has no attribute 'length'.
我的代码如下:
line1var = StringVar()
line1var.set("")
def tobeplaced(value):
global line1var
if line1var.length() == 0:
txtReceipt.insert(END, value)
foo = Button(root, text="foo", command=lambda : tobeplaced("foo")).pack()
什么办法呢?
不是'len(line1var)'工作吗? – ForceBru
@ForceBru:No.'TypeError:'StringVar'类型的对象没有len()'。但是你可以'如果len(line1var.get())== 0:',尽管我更喜欢'如果不是line1var.get():'。 –