How to set focus on Entry widget in Tkinter?

TkinterServer Side ProgrammingProgramming

Let us suppose that there are some widgets present in an application such that we have to focus on a particular widget. By using the focus_set() method, we can activate the focus on any widget and give them priority while executing the application.

Example

#Import tkinter library
from tkinter import *

#Create an instance of tkinter frame
win = Tk()

#Set the geometry of tkinter window
win.geometry("750x250")

#Create an Entry Widget
entry= Entry(win, width= 25)
entry.insert(0,"ttk Entry widget")
entry.pack()

#Set the focus to Entry widget
entry.focus_set()
win.mainloop()

Output

When we run our program, it will display a window with an active entry widget.

raja
Published on 16-Apr-2021 06:57:43
Advertisements