13.2 方法
| 方法 | 描述 |
|---|---|
| bbox(index) | 返回指定字符的矩形边界 |
| config(**options) | 配置Spinbox的属性。具体的属性说明见Spinbox属性说明。 |
| delete(first, last=None) | 删除选中的文本。起始是first,last如果没有定义,则只删除当前字符。 |
| get() | 获得当前控件的内容。返回值是一个字符串 |
| icursor(index) | 移动插入光标到指定的位置。 |
| identify(x, y) | 确认输入的屏幕的坐标点,是否在Spinbox的范围内。 (x,y):屏幕坐标点 返回值:字符串 “buttonup”:上箭头 “buttondown”:下箭头 “entry”:输入框 None:不在spinbox范围内。 |
| index(index) | 获得index指定的数字类型的位置。 |
| insert(index, string) | 在index位置处插入字符。 |
| insert(INSERT,string) | 在插入光标的位置插入字符 |
| insert(END,string) | 追加文本 |
| invoke(element) | 调用Spinbox的按钮。只能时“buttonup”,”buttondown” |
| selection_adjust(index) | 调整选择到index位置。如果index已经被选择,无动作。 |
| selection_clear() | 清除选择 |
| selection_element(element=None) | 选中一个element,如果没有设置这个参数,返回当前选定的element. element指:上箭头、下箭头、输入框 |
13.2.1 bbox(index)
返回包括index指定的字符的矩形框。返回值位(x,y,w,h)的四元组。
import tkinter as tk
root=tk.Tk()
root.geometry('300x240')
tk.Label(root).pack()
b1=tk.Spinbox(root,from_=110,to=115,width=4)
b1.pack()
print(b1.bbox(2))
root.mainloop()
**13.2.2 config(options)
修改Spinbox的配置参数。
13.2.3 delete(first,last=None)
删除输入控件中的内容。参见6.2.2。
13.2.4 get()
获得输入框中的内容。参见6.2.3。
13.2.5 icursor(index)
移动输入光标到指定的位置。参见6.2.4。
13.2.6 identify(x, y)
确认输入的屏幕的坐标点,是否在Spinbox的范围内。
(x,y):屏幕坐标点
返回值:字符串
“buttonup”:上箭头
“buttondown”:下箭头
“entry”:输入框
import tkinter as tk
root=tk.Tk()
root.geometry('300x240')
b1=tk.Spinbox(root,from_=110,to=115,width=14)
b1.pack()
def pos(event):
print(b1.identify(event.x,event.y))
b1.bind('',pos)
root.mainloop()
13.2.7 index(i)
返回数字类型的位置信息。参见6.2.5。
13.2.8 insert(index, string)
在指定的位置处插入字符串。参见6.2.6。
13.2.9 invoke(element)
调用Spinbox的上箭头按钮或者下箭头按钮。也就是说,每调用一次invoke(‘buttonup’)或者invoke(‘buttondown’) 就相当于是按动了一次上箭头按钮或者下箭头按钮,输入框中的数值也会相应的变动。
import tkinter as tk
root=tk.Tk()
root.geometry('300x240')
b1=tk.Spinbox(root,from_=10,to=40)
b1.pack()
def invoke():
b1.invoke('buttonup')
b2=tk.Button(root,text='Invoke',command=invoke)
b2.pack()
root.mainloop()
13.2.10 selection_adjust()
调整输入框中选择区域。参见6.2.8。
13.2.11 selection_clear()
清除选择。参见6.2.9。
13.2.12 selection_element(element=None)
选择指定元素。元素是指:’buttonup’,’buttondown’以及’none’。如果没有输入element,则返回当前选中的元素。不过该方法的实现有个bug,如果不输入任何参数,会返回TclError。