简体   繁体   English

tkinter spinbox 双零

[英]tkinter spinbox double zeroes

I have a spinbox that needs to have double zeroes, like a clock.我有一个需要有双零的旋转框,就像一个时钟。 No matter what I try, I get only 1. Is it even possible to have a spinbox display double zeroes?无论我尝试什么,我都只得到 1。是否有可能让旋转框显示双零?

# all give same options: 0 - 15 - 30 - 45
Spinbox(root, from_=00, to=45, increment=15)
Spinbox(root, values=('00', '15', '30', '45'))

Entirely possible!完全有可能! Use the format= option.使用format=选项。

Spinbox(root, from_=00, to=45, increment=15, format="%02.0f")

That should give you what you need.那应该给你你需要的。 Take a look at the format docs for more information.查看格式文档以获取更多信息。

Now u need to use format() before现在你需要先使用format()

Example in 3.7: 3.7 中的示例:

var = IntVar(root)
var.set("{:02d}".format(time.localtime().tm_sec))
spinbox = ttk.Spinbox(root, textvariable=var, from_=0, to=23, width = 2, format="%02.0f")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM