本文介绍了Tkinter Spinbox Widget 设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 tkinter spinbox:

I have a tkinter spinbox:

sb = Spinbox(frame, from_=1, to=12)

我想将 spinbox 的默认值设置为 4.我该怎么做?

I would like to set the default value of spinbox to 4. How do i do this ?

我已经阅读了 Bryan 建议设置的线程

i have read this thread where Bryan suggests setting

Tkinter.Spinbox(values=(1,2,3,4))
sb.delete(0,"end")
sb.insert(0,2)

但我没有理解它背后的逻辑.

But i did not get the logic behind it.

删除和插入与设置默认值有什么关系?

What has delete and insert to do with setting default values ?

如有任何进一步的见解,我们将不胜感激.

Any further insight would be appreciated.

谢谢

推荐答案

sb.delete(0,"end") 用于从 Spinbox 中删除所有文本,并带有 sb.insert(0,2) 插入数字 2 作为新值.

sb.delete(0,"end") is used to remove all the text from the Spinbox, and with sb.insert(0,2) you insert the number 2 as the new value.

您还可以使用 textvariable 选项设置默认值:

You can also set a default value with the textvariable option:

var = StringVar(root)
var.set("4")
sb = Spinbox(root, from_=1, to=12, textvariable=var)

这篇关于Tkinter Spinbox Widget 设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 04:09