Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Using the Tkinter Scale Widget

  • Vijaykrishna RamVijaykrishna Ram
  • April 29, 2020
  • Tkinter
Using the Tkinter Scale Widget

Hello everyone! In this part of our Tkinter Tutorial, we shall cover yet another widget – the Tkinter Scale widget.

This is a useful widget to have, if you want to display a scale of any kind on your application.

We’ll demonstrate how you can use this widget, using a simple example. Let’s get started!


Basic Tkinter Scale Widget Options

We can use this widget when we want the user to enter a numerical value, bounded within certain limits.

The user can move across the scale and select the appropriate value for the input.

To use this, the basic options are of the following format:

scale_widget = tk.Scale(master, from_, to, orient)

Here, master is the Tkinter master object, which is necessary for any Tkinter GUI application to run.

The from_ and to keyword arguments specify the range of the slider values.

Finally, the orientation orient can be either “horizontal” or “vertical”.

There is one more optional argument called resolution, which specifies the numerical resolution of the values.

For example, the default resolution is 1, which will ensure that all values are rounded to the nearest integer. You can try tweaking with this parameter as per your need.

To use the current value of the Tkinter scale widget, you can simply call scale_widget.get(). And to set the Tkinter scale widget, you can call scale_widget.set(value).

Let’s now look at an example to illustrate what this means.


Using the Tkinter Scale Widget – Build a Scale for our Application

Let’s build a horizontal scale for our dummy application, which consists of integer values from 0 to 100.

This means that the numeric resolution is 1.

import tkinter as tk
from tkinter import messagebox

# Create the master object
master = tk.Tk()

# Create a Scale Widget
scale_widget = tk.Scale(master, orient="horizontal", resolution=1,
                        from_=0, to=100)

# And a label for it
label_1 = tk.Label(master, text="Scale")

# Use the grid geometry manager to put the widgets in the respective position
label_1.grid(row=0, column=0)
scale_widget.grid(row=0, column=1)

# The application mainloop
tk.mainloop()

Output

Scale Example 1
Scale Example 1

Alright! This works as expected, and we have our Tkinter scale widget displaying values from 0 to 100.

Let’s now add a Button widget to our application.

When we click on the button after setting the scale value, we’ll invoke a function call to output a Message Box alert, which will display what value we chose.

Let’s add the Button widget to our program.

button = tk.Button(master, text="Click", command=buttonCallback)
button.grid(row=1, column=1)

Here, the command argument specifies the function that will get called when this button gets clicked.

We will call a function called buttonCallback, which handles this event for us.

def buttonCallback():
    global scale_widget
    messagebox.showinfo("Message", "You have chosen value {}".format(scale_widget.get()))

I’m using the scale_widget on the global scope, so that we can get the value using scale_widget.get(). This value will get printed on a message box.

As an add on, I’ll also increase the default frame size from the standard “200×200”, to a larger “300×300” window, using master.geometry().

master.geometry("300x300")

I’ll post the complete code now.

import tkinter as tk
from tkinter import messagebox

# Create the master object
master = tk.Tk()

master.geometry("300x300")

# Create a Scale Widget
scale_widget = tk.Scale(master, orient="horizontal", resolution=1,
                        from_=0, to=100)

# And a label for it
label_1 = tk.Label(master, text="Scale")

# Use the grid geometry manager to put the widgets in the respective position
label_1.grid(row=0, column=0)
scale_widget.grid(row=0, column=1)

def buttonCallback():
    global scale_widget
    messagebox.showinfo("Message", "You have chosen value {}".format(scale_widget.get()))

button = tk.Button(master, text="Click", command=buttonCallback)
button.grid(row=1, column=1)

# The application mainloop
tk.mainloop()

Now, let’s look at the output.

Tkinter Scale Example
Tkinter Scale Example

Indeed, when you click on the Button, after setting the scale value, the correct number is displayed!


Conclusion

In this tutorial, we looked at using the Tkinter Scale widget.

In the upcoming articles, we’ll cover a few more widgets, so stay tuned for more!


Vijaykrishna Ram
Vijaykrishna Ram
Articles: 99
How to Perform the Python Division Operation?
Previous Post How to Perform the Python Division Operation?
Next Post Using Python String format_map()
Using Python String format_map()

Related Posts

Tkinter IntVar – Tkinter Tutorial with Examples

Tkinter IntVar – Tkinter Tutorial with Examples

  • July 5, 2026
Tkinter StringVar with Examples – Tkinter Tutorial

Tkinter StringVar with Examples – Tkinter Tutorial

  • July 5, 2026
Tkinter GUI Widgets

Tkinter GUI Widgets

  • April 24, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.