zoukankan      html  css  js  c++  java
  • Tkinter 之Scale滑块标签

    一、参数说明

    语法作用
    Scale(window, label="滑块") 滑块标题
    Scale(window, label="滑块", from_=0) 滑块最小值为0
    Scale(window, label="滑块", to=100) 滑块最大值为100
    Scale(window, label="滑块", length=200) 滑块长度为200
    Scale(window, label="滑块", orient = tk.HORIZONTAL) 滑块水平方向显示
    Scale(window, label="滑块", resolution=0.01) 滑块值的精度为0.01
    Scale(window, label="滑块", digits = 8) 设置显示的位数为8
    Scale(window, label="滑块", command=select) 滑动时的回调
    scale.get() 获取当前滑块位置的值
    scale.set(10) 设置滑块的值

    二、代码示例

    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("Scale参数说明")
    # 设置窗口初始位置在屏幕居中
    window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
    # 设置窗口图标
    window.iconbitmap("./image/icon.ico")
    # 设置窗口宽高固定
    window.resizable(0, 0)
    
    """scale参数.
    
            Valid resource names: activebackground, background, bigincrement, bd,
            bg, borderwidth, command, cursor, digits, fg, font, foreground, from,
            highlightbackground, highlightcolor, highlightthickness, label,
            length, orient, relief, repeatdelay, repeatinterval, resolution,
            showvalue, sliderlength, sliderrelief, state, takefocus,
            tickinterval, to, troughcolor, variable, width."""
    def select(v):
        print(v)
    # 创建一个1到100的滑块, 精度为0.01, 显示的最大位数为8
    scale = tk.Scale(window, label="滑块", length = 400, from_=1, to = 100, bg="#bbb", fg = "#f00", orient = tk.HORIZONTAL, command=select, resolution=0.01, digits = 8)
    scale.pack()
    
    def getScaleValue():
        print(scale.get())
    
    def setScaleValue():
        scale.set(10)
    tk.Button(window, text="get value", width=30, pady=5, command=getScaleValue).pack()
    tk.Button(window, text="set value", width=30, pady=5, command=setScaleValue).pack()
    window.mainloop()
    

    三、效果图

  • 相关阅读:
    Sencha, the nightmare!
    最近这一年
    SharePoint 是哪些人设计、开发的?
    用 Excel 测试“绘制两点间连线”的算法
    实现一个基于 SharePoint 2013 的 Timecard 应用(下)
    实现一个基于 SharePoint 2013 的 Timecard 应用(中)
    实现一个基于 SharePoint 2013 的 Timecard 应用(上)
    ASP.NET 在 Windows Azure 环境中使用基于 SQLServer 的 Session
    SQLServer 查询使用键查找时锁申请及释放顺序
    由delete导致的超时已过期问题
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11790804.html
Copyright © 2011-2022 走看看