Tkinter set focus to 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 to adjust focus on the last tk.Entry (.) Widget?

+4
source share
1 answer

Use a method focus_setthat is common to all widgets:

entry = tk.Entry(...)
entry.place(...)
entry.focus_set()
+11
source

Source: https://habr.com/ru/post/1529920/


All Articles