How to set focus on Entry widget in Tkinter?


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.

Updated on: 16-Apr-2021

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements