Tkinter set focus on Entry widget
Asked Answered
C

1

19

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?

Custom answered 4/3, 2014 at 2:40 Comment(2)
Use help(tk.Entry).Plaything
Possible duplicate of Setting focus to specific TKinter entry widgetTatiana
C
28

Use the focus_set method which is common to all widgets:

entry = tk.Entry(...)
entry.place(...)
entry.focus_set()
Committeeman answered 4/3, 2014 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.