Python GUI----Scale

Source: Internet
Author: User

Scale is the number range for the output limit, and you can specify a maximum value, a minimum value, and a stride value. The scale component defaults to vertical, a maximum value of 100, a minimum value of 0, and a step distance of 1

1. Create a scale

From tkinter Import *root = Tk () scale (root). Pack () Root.mainloop ()


2. Change the default value

From tkinter Import *root = Tk () scale (root,      from_ = -500,         #设置最大值 to      = $,             #设置最小值      Resolution = 5,
   
     #设置步距值      Orient = horizontal   #设置水平方向      ). Pack () Root.mainloop ()
   

3.Scale bound variable
From tkinter Import *root = Tk () v = stringvar () scale (root,      from_ = 0,                 #设置最小值 to      = 100.0,                #设置最大值      Resol Ution = 0.0001,       #设置步距值      orient = horizontal,       #设置水平方向      variable = v               #绑定变量      ). Pack () print (V.get ( ))                  #Scale的值一致root. Mainloop ()
4. Use the callback function to print the current value
From tkinter Import *root = Tk () def printscale (text): Print    (' Text = ', text)    print (' v = ', v.get ()) v = stringvar () scale (root,      from_ = 0,                #设置最小值 to      = 100.0,               #设置最大值      Resolution = 0.0001,      #设置步距值      Orient = horizontal,      #设置水平方向      variable = V,             #绑定变量      command = Printscale      #设置回调函数      ). Pack () Print (V.get ()) Root.mainloop ()
This callback function has a parameter, this value is the value of the current scale, each move a step will be called once this function, only ensure that the last one will definitely be called, the middle of the may not be called, by the above example can see the value is exactly the same.
5. Set the Label property of the scale label
From tkinter Import *root = Tk () scale (root,      from_ = 0, to                     = 100.0,                     orient = horizontal,            label = ' Choice: ',        #设置标签值      ). Pack () Root.mainloop ()
6. Set/Get the value of scale
From tkinter Import *root = Tk () SL = scale (root) sl.set      #将Scale的值设置为50print (Sl.get ())  #打印当前的Scale的值sl. Pack () Root.mainloop ()



Python GUI----Scale

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.