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?
Focus is used to refer to the widget or window which is currently accepting input. Widgets can be used to restrict the use of mouse movement, grab focus, and keystrokes out of the bounds.
It focuses the widget and makes them active until the termination of the program.
focus_set() method- This method is used to set the focus on the desired widget if and only if the master window is focused.
PythonTkinter entry textvariable textvariable is used to provide value through a variable. value can be Integer or String. for integer : IntVar() keyword is used. for String: StringVar() keyword is used.
Use the focus_set
method which is common to all widgets:
entry = tk.Entry(...)
entry.place(...)
entry.focus_set()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With