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.


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

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

#Set the geometry of window

#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) .5, rely= .5, anchor= CENTER) .5, rely= .6, anchor = CENTER)



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

Published on 26-May-2021 12:06:36