Tkinter Spinbox

Python - Tkinter Spinbox: Spinbox小部件是一个标准的Tkinter的Entry小窗口部件的变体,它可以用来选择从一个固定的值.
 
Spinbox小部件是一个标准的Tkinter的Entry小窗口部件的变体,它可以用来选择从一个固定的值.

语法:

这里是一个简单的语法来创建这个widget:

w = Spinbox( master, option, ... )

参数:

  • master: 这代表了父窗口.

  • options: 下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.

OptionDescription
activebackgroundThe color of the slider and arrowheads when the mouse is over them.
bgThe color of the slider and arrowheads when the mouse is not over them.
bdThe width of the 3-d borders around the entire perimeter of the trough, and also the width of the 3-d effects on the arrowheads and slider. Default is no border around the trough, and a 2-pixel border around the arrowheads and slider.
commandA procedure to be called whenever the scrollbar is moved.
cursorThe cursor that appears when the mouse is over the scrollbar.
disabledbackgroundThe background color to use when the widget is disabled.
disabledforegroundThe text color to use when the widget is disabled.
fgText color.
fontThe font to use in this widget.
formatFormat string. No default value.
from_The minimum value. Used together with to to limit the spinbox range.
justifyDefault is LEFT
reliefDefault is SUNKEN.
repeatdelayTogether with repeatinterval, this option controls button auto-repeat. Both values are given in milliseconds.
repeatintervalSee repeatdelay.
stateOne of NORMAL, DISABLED, or "readonly". Default is NORMAL.
textvariableNo default value.
toSee from.
validateValidation mode. Default is NONE.
validatecommandValidation callback. No default value.
valuesA tuple containing valid values for this widget. Overrides from/to/increment.
vcmdSame as validatecommand.
widthWidget width, in character units. Default is 20.
wrapIf true, the up and down buttons will wrap around.
xscrollcommandUsed to connect a spinbox field to a horizontal scrollbar. This option should be set to the set method of the corresponding scrollbar.

方法:

spinbox对象有这些方法:

Methods & Description
delete(startindex [,endindex])
This method deletes a specific character or a range of text.
get(startindex [,endindex])
This method returns a specific character or a range of text.
identify(x, y)
Identifies the widget element at the given location.
index(index)
Returns the absolute value of an index based on the given index.
insert(index [,string]...)
This method inserts strings at the specified index location.
invoke(element)
Invokes a spinbox button.

例子:

自行尝试下面的例子:

from Tkinter import *

master = Tk()

w = Spinbox(master, from_=0, to=10)
w.pack()

mainloop()

这将产生以下结果:

 

转载于:https://www.cnblogs.com/tkinter/p/5628827.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值