Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place the cursor on an Entry widget by default when the window loads?

Tags:

python

tkinter

So, I have three entry widgets on my window and I want that the cursor should be there on the first entry widget, so that when the window pops up the user can directly start writing on the first entry box, without having to click on the first box and then start writing.

input1 = Entry(root)
input1.pack()
input2 = Entry(root)
input2.pack()
input3 = Entry(root)
input3.pack()

1 Answers

Use w.focus_set()

import tkinter as tk

root = tk.Tk()      
input1 = tk.Entry(root)
input1.pack()
input1.focus_set()

input2 = tk.Entry(root)
input2.pack()
input3 = tk.Entry(root)
input3.pack()
root.mainloop()
like image 141
Tls Chris Avatar answered Feb 02 '26 12:02

Tls Chris