22.图形交互tkinter--Scale

2018-09-04  本文已影响0人  DonkeyJason
Scale----范围控件;显示一个数值刻度,为输出限定范围的数字区间

实例1--设置两个Scale条

from tkinter import *


root =Tk()

Scale(root, from_=0, to =42).pack()
Scale(root, from_=0, to =200,orient =HORIZONTAL).pack()


mainloop()  
Scale1

竖直从0-42,水平从0-200,长条实际长度及像素默认,可以设置,看下面的例子3。

实例2--获取Scale确定范围坐标

from tkinter import *


root =Tk()

s1 =Scale(root, from_=0, to =42)
s1.pack()


s2 = Scale(root, from_=0, to =200)
s2.pack()

def show():
    print(s1.get(),s2.get())



Button(root,text="获取位置",command = show).pack()

mainloop()  
Scale2

无精度,没规定步进精度,没走一下为1,也没有设置显示像素,0-42和0-200像素都一样,看起来十分不美观,点击获取可以获取到两个范围值。

实例3--获取Scale确定范围坐标

from tkinter import *

app = Tk()
#tickinterval步进刻度,resolution精度每一步走5,length = 200像素

S1 = Scale(app, from_= 0, to = 42, tickinterval = 5, resolution =5, length = 200)
S1.pack()#包装

S2 =Scale(app, from_ = 0, to = 200, tickinterval = 10, orient = HORIZONTAL, length = 600)
S2.pack()

def show():
    print(S1.get(), S2.get())
    

Button(app, text = "获取位置",command = show).pack()



mainloop()
Scale3

Scale中的几个参数设置,你会了吗?

上一篇 下一篇

猜你喜欢

热点阅读