HeightVar = StringVar() # now created before creating Entry
HeightEntry = Entry(master, textvariable=HeightVar)
HeightVar.set("a default value") # now called on the StringVar, not on Entry
HeightValue = HeightVar.get() # returns "a default value" from previous line
您也可以在没有StringVar的情况下使用delete和insert:
HeightEntry.delete(0, 'end') # needed only if Entry contains text
HeightEntry.insert(0, 'a default value')
在创建
Entry
之前先创建StringVar
。不要调用Entry.set
来设置值,而是调用StringVar.set
:您也可以在没有
StringVar
的情况下使用delete
和insert
:有关更改大小和字体的信息,请参见Fredrik Lundh的The Tkinter Entry Widget或John Shipman的The Entry Widget
相关问题 更多 >
编程相关推荐