Scale of Tkinter tutorials

Source: Internet
Author: User
'''Scale of Tkinter tutorials '''
# Scale is the number range of the output range. You can specify the maximum value, minimum value, and stride value.
'''1. Create a Scale '''
From Tkinter import *
Root = Tk ()
Scale (root). pack ()
Root. mainloop ()
# Create a vertical Scale. The maximum value is 100, the minimum value is 0, and the step value is 1. This parameter is also the default Scale setting.
'''2. Change these three parameters to generate a horizontal Scale. The minimum value is-500, the maximum value is 500, and the stride value is 5 '''
#-*-Coding: cp936 -*-
From Tkinter import *
Root = Tk ()
Scale (root,
From _ =-500, # set the maximum value
To = 500, # set the minimum value
Resolution = 5, # Set the stride Value
Orient = HORIZONTAL # Set the HORIZONTAL direction
). Pack ()
Root. mainloop ()
# Note the usage of from _ and add "_" to it to avoid conflict with the keyword from.

'''3. Bind Variable '''
#-*-Coding: cp936 -*-
From Tkinter import *
Root = Tk ()
V = StringVar ()
Scale (root,
From _ = 0, # set the minimum value
To = 100.0, # set the maximum value
Resolution = 0.0001, # Set the stride Value
Orient = HORIZONTAL, # sets the HORIZONTAL direction
Variable = v # bind a variable
). Pack ()
Print v. get ()
Root. mainloop ()
# The value of v is the same as that of Scale.
'''4. Use the callback function to print the current value '''
#-*-Coding: cp936 -*-
From Tkinter import *

Root = Tk ()
Def printScale (text ):
Print 'text = ', text
Print 'v = ', v. get ()
V = StringVar ()
Scale (root,
From _ = 0, # set the minimum value
To = 100.0, # set the maximum value
Resolution = 0.0001, # Set the stride Value
Orient = HORIZONTAL, # sets the HORIZONTAL direction
Variable = v, # bind a variable
Command = printScale # Set the callback function
). Pack ()
Print v. get ()
Root. mainloop ()
# This callback function has a parameter. The value is the current Scale value. This function will be called every time you move a step, only to ensure that the last one will be called.
# It may not be called. We can see from the above example that the values of the two are exactly the same.

'''5. it can be understood that the Scale value is an integer. When the output is displayed, it will be converted to a string. For example, 1.2 can be converted to 1.2 or 1.2000 '''
# The digits attribute controls the number of digits displayed. The data in the preceding example is displayed in 8 bits. A value of 0 is added to the last bits.
#-*-Coding: cp936 -*-
From Tkinter import *

Root = Tk ()
Def printScale (text ):
Print 'text = ', text
Print 'v = ', v. get ()
V = StringVar ()
Scale (root,
From _ = 0, # set the minimum value
To = 100.0, # set the maximum value
Resolution = 0.0001, # Set the stride Value
Orient = HORIZONTAL, # sets the HORIZONTAL direction
Digits = 8, # set the number of digits to 8
Variable = v, # bind a variable
Command = printScale # Set the callback function
). Pack ()
Print v. get ()
Root. mainloop ()


'''6. Set the label attribute of Scale '''
#-*-Coding: cp936 -*-
From Tkinter import *

Root = Tk ()
Scale (root,
From _ = 0, # set the maximum value
To = 100.0, # set the minimum value
Orient = HORIZONTAL, # sets the HORIZONTAL direction
Label = 'choice: ', # Set the label Value
). Pack ()
Root. mainloop ()
# The value set by label is displayed above the horizontal Scale for prompt information.

'''7. Set/obtain the Scale value '''
#-*-Coding: cp936 -*-
From Tkinter import *
Root = Tk ()
Sl = Scale (root)
Sl. set (50) # set the Scale value to 50
Print sl. get () # print the current Scale value
Sl. pack ()
Root. mainloop ()
# Slider is located in the middle, sl. set (50) takes effect, and the print value is 50.

# Author: jcodeer
# Blog: jcodeer.cublog.cn
# Email: jcodeer@126.com

 

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.