tkinter中的spinBox样式详解

简介

【spinbox】是增减框,除了可以用于增减数字之外,还可用于元组内容的遴选,如下图所示

在这里插入图片描述

代码如下

import tkinter as tk
import tkinter.ttk as ttk
 
root = tk.Tk()
root.title("Spinbox 演示")

frm = tk.LabelFrame(root, text="基础功能")
frm.pack(side = tk.TOP)

ttk.Spinbox(frm, width=10, from_=1, to=10, increment=1).pack(side=tk.LEFT)
ttk.Spinbox(frm, width=10, from_=0.1, to=5, increment=0.1).pack(side=tk.LEFT)
ttk.Spinbox(frm, width=10, values=("A", "B", "C", "D")).pack(side=tk.LEFT)
root.mainloop()

其中,【from_】【to】【increment】这三个参数用于设置数字范围与步长;【values】则通过一个有序列表,来供用户选择。

更多样式示例

Spinbox支持多种样式的设置,具体效果如下

在这里插入图片描述

其中各参数含义如下

参数/缩写
background/bg背景颜色
foreground/fg前景色
buttonbackground箭头背景色
buttonup向上调节箭头的样式,默认raised
buttondownrelief向下调节箭头的样式,默认raised
relief边框样式,默认raised
width宽度,以字符宽度为单位,默认20
borderwidth边框宽度
insertwidth光标宽度
insertbackground光标颜色
insertborderwidth光标的边框宽度
state组件状态,默认normal
disabledbackgrounddisabled状态下的背景颜色
disabledforegrounddisabled状态下的前景颜色
selectbackground文本被选中时的背景色
selectforeground文本被选中时的前景色
selectborderwidth文本被选中时的边框宽度
justify输入框中的文本对齐方式,默认left
insertofftime光标闪烁时灭掉的时间,单位是毫秒
insertontime光标闪烁时亮着的时间,单位是毫秒
highlightthickness高亮边框的宽度
highlightbackground没有获得焦点的时候高亮边框的颜色
highlightcolor获得焦点的时候高亮边框的颜色
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微小冷

请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值