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


Tkinter Entry widget is an input widget that supports only single-line user input. It accepts all the characters in the text field unless or until there are no restrictions set for the input. We can change the value of the Entry widget with the help of the Scale widget. The Scale widget contains a lower value and a threshold that limits the user to adjust the value in a particular range.

To update the value in the Entry widget while updating the value of Scale widget, we have to create a variable that has to be given to both the scale and the entry widget.

Example

#Import the Tkinter Library
from tkinter import *
from tkinter import ttk

#Create an instance of Tkinter Frame
win = Tk()

#Set the geometry of window
win.geometry("700x350")

#Create an Integer Variable to set the initial value of Scale
var = IntVar(value=10)

#Create an Entry widget
entry = ttk.Entry(win,width= 45,textvariable=var)
scale = Scale(win, from_=10, to=200, width= 20, orient="horizontal", variable=var)

entry.place(relx= .5, rely= .5, anchor= CENTER)
scale.place(relx= .5, rely= .6, anchor = CENTER)

win.mainloop()

Output

Running the above code will display an Entry widget and a Scale which can be used to update the value in the Entry widget.

Updated on: 26-May-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements