18

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Cyrus TNZ63
  • 209
  • 1
  • 2
  • 6
  • 2
    Use `help(tk.Entry)`. – User Mar 04 '14 at 08:37
  • Possible duplicate of [Setting focus to specific TKinter entry widget](https://stackoverflow.com/questions/13626406/setting-focus-to-specific-tkinter-entry-widget) – Aran-Fey Apr 15 '18 at 11:05

1 Answers1

27

Use the focus_set method which is common to all widgets:

entry = tk.Entry(...)
entry.place(...)
entry.focus_set()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685