更改python中的默认tkinter条目值

2024-10-04 09:21:58 发布

您现在位置:Python中文网/ 问答频道 /正文

checkLabel = ttk.Label(win,text = "  Check Amount  ", foreground = "blue")
checkLabel.grid(row = 0 , column = 1)
checkEntry = ttk.Entry(win, textvariable = checkVariable)
checkEntry.grid(row = 1, column = 1, sticky = 'w')

如何更改defualt entry字段,使其不显示0?在


Tags: textcheckcolumnblueamountwinlabelgrid
2条回答

在创建Entry对象之前,将checkVariable的值设置为''(空字符串)?要使用的语句是

checkVariable.set('')

但是checkVariable必须是StringVar,如果需要整数值,则必须自己将输入值转换为整数。在

使用entry小部件的函数.insert().delete()。这是一个例子。在

entry = tk.Entry(root)
entry.insert(END, "Hello") # this will start the entry with "Hello" in it
# you may want to add a delay or something here. 
entry.delete(0, END) # this will delete everything inside the entry
entry.insert(END, "WORLD") # and this will insert the word "WORLD" in the entry.

另一种方法是使用Tkinter StrVar。下面是一个使用str变量的示例。在

^{pr2}$

相关问题 更多 >