Search code examples
python-3.xtkinterwidgetcarettkinter-entry

Set default caret position inside entry widget in Tkinter Python


I want to set the default cursor location inside the entry widget when I run the program.

So when I run it I don't have to click inside the widget to start typing.

Here is my minimal code:

import tkinter as tk

root = tk.Tk()

e = tk.Entry(root)
e.pack()

tk.mainloop()

Solution

  • Simply call the focus method for the widget:

    import tkinter as tk
    
    root = tk.Tk()
    
    e = tk.Entry(root)
    e.pack()
    e.focus()
    
    tk.mainloop()