zoukankan      html  css  js  c++  java
  • Tkinter 之ScrollBar滚动条标签

    一、参数说明

    参数作用
    background (bg) 设置背景颜色
    borderwidth (bd) 指定边框宽度,通常是 2 像素
    cursor  指定当鼠标在上方飘过的时候的鼠标样式
    orient 指定绘制 "horizontal"(垂直滚动条)还是 "vertical"(水平滚动条)
    highlightbackground  指定当滚动条没有获得焦点的时候高亮边框的颜色
    highlightcolor   指定当滚动条获得焦点的时候高亮边框的颜色
    jump  指定当用户拖拽滚动条时的行为
    relief   指定边框样式,  默认值是 "sunken"
    command

     当滚动条更新时回调的函数
    通常的是指定对应组件的 xview() 或 yview() 方法

    takefocus  指定该组件是否接受输入焦点(用户可以通过 tab 键将焦点转移上来),  默认值是 True
    width 设置滚动条的宽度, 默认值是 16 像素

    ScrollBar函数列表:

    activate(element) 

    -- 显示 element 参数指定的元素的背景颜色和样式

    -- element 参数可以设置为:"arrow1"(箭头1),"arrow2"(箭头2)或 "slider"(滑块)

    delta(deltax, deltay)

    -- 给定一个鼠标移动的范围 deltax 和 deltay(像素为单位,deltax 表示水平移动量,deltay 表示垂直移动量),然后该方法返回一个浮点类型的值(范围 -1.0 ~ 1.0)

    -- 这通常在鼠标绑定上使用,用于确定当用户拖拽鼠标时滑块的如何移动

    fraction(x, y)

    -- 给定一个像素坐标 (x, y),该方法返回最接近给定坐标的滚动条位置(范围 0.0 ~ 1.0)

    get()

    -- 返回当前滑块的位置 (a, b)

    -- a 值表示当前滑块的顶端或左端的位置,b 值表示当前滑块的底端或右端的位置(范围 0.0 ~ 1.0)

    identify(x, y)

    -- 返回一个字符串表示指定位置下(如果有的话)的滚动条部件

    -- 返回值可以是:"arrow1"(箭头1),"arrow2"(箭头2)、"slider"(滑块)或 ""(啥都没有)

    set(*args)

    -- 设置当前滚动条的位置

    -- 如果设置则需要两个参数 (first, last),first 表示当前滑块的顶端或左端的位置,last 表示当前滑块的底端或右端的位置(范围 0.0 ~ 1.0)

    二、代码示例

    import tkinter as tk
    
    window = tk.Tk()
    # 设置窗口大小
    winWidth = 600
    winHeight = 400
    # 获取屏幕分辨率
    screenWidth = window.winfo_screenwidth()
    screenHeight = window.winfo_screenheight()
    
    x = int((screenWidth - winWidth) / 2)
    y = int((screenHeight - winHeight) / 2)
    
    # 设置主窗口标题
    window.title("ScrollBar参数说明")
    # 设置窗口初始位置在屏幕居中
    window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
    # 设置窗口图标
    window.iconbitmap("./image/icon.ico")
    # 设置窗口宽高固定
    window.resizable(0, 0)
    
    """scrollbar 参数.
    
            Valid resource names: activebackground, activerelief,
            background, bd, bg, borderwidth, command, cursor,
            elementborderwidth, highlightbackground,
            highlightcolor, highlightthickness, jump, orient,
            relief, repeatdelay, repeatinterval, takefocus,
            troughcolor, width."""
    scroll_bar = tk.Scrollbar(window)
    scroll_bar.pack(side = tk.RIGHT, fill = tk.Y)
    
    list_box = tk.Listbox(window)
    
    for i in range(1000):
        list_box.insert(tk.END, i)
    list_box.config(yscrollcommand = scroll_bar.set)
    list_box.pack(expand=1, fill = tk.BOTH)
    
    scroll_bar.config(command = list_box.yview, width = 16)
    
    window.mainloop()
    

    三、效果图

     

  • 相关阅读:
    随 机 贪 心
    QWidget,QMainWindow和QDialog的区别
    粒子系统和Ogre 3D扩展 -----OGRE 3D 1.7 Beginner‘s Guide中文版 第十章(终章)
    setStyleSheet 设置多个属性
    Ogre 3D的启动顺序 -----OGRE 3D 1.7 Beginner‘s Guide中文版 第九章
    合成器框架 -----OGRE 3D 1.7 Beginner‘s Guide中文版 第八章
    Ogre 3D与材质 -----OGRE 3D 1.7 Beginner‘s Guide中文版 第七章
    场景管理器 -----OGRE 3D 1.7 Beginner‘s Guide中文版 第六章
    使用Ogre 3D 运动模型 -----OGRE 3D 1.7 Beginner‘s Guide中文版 第五章
    摄像机,光源和阴影 -----OGRE 3D 1.7 Beginner‘s Guide中文版 第四章
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11791563.html
Copyright © 2011-2022 走看看