• Python tkinter--第13章数值调整控件(Spinbox)方法


    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()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    **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()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    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()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    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。

  • 相关阅读:
    MYSQL之外键约束
    git修改远程仓库地址
    【云原生】K8S master节点更换IP以及master高可用故障模拟测试
    算法leetcode|84. 柱状图中最大的矩形(rust重拳出击)
    Postgresql源码(77)plpgsql中参数传递和赋值
    Arctic开源!网易数帆×华泰证券,推动湖仓一体落地
    【分享】xpath的路径表达式
    盘点5个C#开发的、可用于个人博客的系统
    【笔记】ABAQUS弹塑性分析
    【后端面经-数据库】Redis数据结构和底层数据类型
  • 原文地址:https://blog.csdn.net/weixin_42272768/article/details/100786067