tkinter Scale滑块

鼠标拖动和绑定鼠标滚轮移动:

import threading
from tkinter import *
root = Tk()
v = StringVar()
s1 = Scale(root,from_ = 0,to = 42)
s1.pack()
s2 = Scale(root,
      from_ = 0,#设置最小值
      to = 200,#设置最大值
      orient = HORIZONTAL,#设置横向
      # resolution=5,#设置步长
      # tickinterval = 10,#设置刻度
      length = 600,# 设置像素
      variable = v)#绑定变量
s2.pack()
print(v.get())
def wheel(e):
    if e.delta > 0:
        s2.set(s2.get()+1)
    else:
        s2.set(s2.get()-1)

def show():
    print(s2.get())
    timer = threading.Timer(1, show)
    timer.start()

s2.bind("<MouseWheel>", wheel)
# Button(root,text = '获取位置',command = show).pack()#用command回调函数获取位置
timer = threading.Timer(1, show)
timer.start()
mainloop()

 

posted @ 2019-03-20 00:28  静静别跑  阅读(1069)  评论(0编辑  收藏  举报