How to change the Entry Widget Value with a Scale in Tkinter?

The Tkinter Entry widget accepts single-line user input and can be synchronized with a Scale widget to create an interactive value selector. By sharing a common variable between both widgets, changes to the Scale automatically update the Entry value.

Key Components

To link an Entry widget with a Scale widget, you need:

  • IntVar() or DoubleVar() − A Tkinter variable shared between widgets
  • textvariable parameter in Entry widget
  • variable parameter in Scale widget

Basic Example

Here's how to create a synchronized Entry and Scale widget ?

import tkinter as tk
from tkinter import ttk

# Create main window
root = tk.Tk()
root.geometry("400x200")
root.title("Entry-Scale Synchronization")

# Create shared variable
value_var = tk.IntVar(value=50)

# Create Entry widget
entry = ttk.Entry(root, width=20, textvariable=value_var)
entry.pack(pady=20)

# Create Scale widget
scale = tk.Scale(root, from_=0, to=100, orient="horizontal", 
                variable=value_var, length=300)
scale.pack(pady=20)

# Add label to show current value
label = tk.Label(root, text="Adjust the scale or type in the entry")
label.pack(pady=10)

root.mainloop()

Advanced Example with Validation

This example includes input validation and callback functions ?

import tkinter as tk
from tkinter import ttk

def on_value_change(*args):
    """Callback function triggered when value changes"""
    current_value = value_var.get()
    status_label.config(text=f"Current Value: {current_value}")

# Create main window
root = tk.Tk()
root.geometry("500x250")
root.title("Advanced Entry-Scale Example")

# Create shared variable with trace
value_var = tk.DoubleVar(value=25.0)
value_var.trace('w', on_value_change)

# Create widgets
title_label = tk.Label(root, text="Temperature Control (°C)", 
                      font=("Arial", 14, "bold"))
title_label.pack(pady=10)

entry = ttk.Entry(root, width=15, textvariable=value_var, justify="center")
entry.pack(pady=10)

scale = tk.Scale(root, from_=0, to=50, orient="horizontal",
                variable=value_var, length=350, resolution=0.5)
scale.pack(pady=10)

status_label = tk.Label(root, text=f"Current Value: {value_var.get()}", 
                       fg="blue")
status_label.pack(pady=10)

# Create reset button
def reset_value():
    value_var.set(25.0)

reset_btn = ttk.Button(root, text="Reset to Default", command=reset_value)
reset_btn.pack(pady=10)

root.mainloop()

Key Parameters

Parameter Widget Description
textvariable Entry Links Entry to a Tkinter variable
variable Scale Links Scale to a Tkinter variable
from_, to Scale Minimum and maximum values
resolution Scale Step size for Scale values

Variable Types

Choose the appropriate Tkinter variable type based on your data:

  • IntVar() − For integer values
  • DoubleVar() − For floating-point numbers
  • StringVar() − For text values

Conclusion

Synchronizing Entry and Scale widgets creates intuitive user interfaces where users can input values either by typing or sliding. Use IntVar() or DoubleVar() as the shared variable, and add trace callbacks for real-time updates.

Updated on: 2026-03-25T20:47:52+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements