Cyrus TNZ63
Cyrus TNZ63

Reputation: 219

Tkinter set focus on Entry widget

Here is my code:

import tkinter as tk
userData = tk.Tk()
nbdays = tk.IntVar()
mainframe = tk.Frame(userData, relief= 'raised', borderwidth=1)
tk.Label(mainframe, text = 'Number of days', font = 10).place(x=2, y = 30)
tk.Entry(mainframe, width= 8, textvariable = nbdays).place(x= 200, y= 30)

[....]

How do I set the focus on that last tk.Entry(.) widget?

Upvotes: 19

Views: 29277

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385860

Use the focus_set method which is common to all widgets:

entry = tk.Entry(...)
entry.place(...)
entry.focus_set()

Upvotes: 28

Related Questions