2

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 Answers1

3

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()
Tls Chris
  • 3,564
  • 1
  • 9
  • 24
  • Thanks for the help, Can you also tell how to add some internal left padding into the Entry widget so that the content doesn't get smooshed into the border of the widget. I tried ipadx but it doesn't work. –  Jun 05 '20 at 20:11
  • It may be best to put the Entries inside a Frame instead of in root. `frame = tk.Frame( padx = 5, pady = 5 )`. This creates some space around the enclosed widgets. Otherwise try searching for something on SO. The `grid` geometry manager includes padx and pady. Use this instead of `pack`. `input1.grid( padx = 5, pady = 5 )`. I hardly ever use `pack`. It may have similar options. – Tls Chris Jun 05 '20 at 20:36
  • `pack` also has padx, pady as options. `input1.pack( padx = 5 )` moves the Entry away from the left and right sides of the container it is in. There are also ipadx and ipady options. – Tls Chris Jun 05 '20 at 20:43
  • Actually I am using grid in my actual code, this is just a sample code that I had put up here. padx and pady are actually the external padding, but I want internal padding like the text within the box should not be starting from the very left, it should leave some space at the beginning. –  Jun 05 '20 at 20:48
  • [Try this question] (https://stackoverflow.com/questions/46460265/tkinters-grid-geometry-manager-ignoring-ipadx-argument). – Tls Chris Jun 05 '20 at 20:59