Python Forum

Full Version: Tkinter focus
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import tkinter as tk
window=tk.Tk()
window.title('Impedance simulation')
window.geometry('900x700')

entry1=tk.Entry(window,show=None,textvariable=tk.StringVar(value=1))
entry2=tk.Entry(window,show=None,textvariable=tk.StringVar(value=2))
entry3=tk.Entry(window,show=None,textvariable=tk.StringVar(value=3))
entry1.pack()
entry2.pack()
entry3.pack()

def locate(key):
    print(window.focus_get())

window.bind('<Key>', locate)
window.mainloop()
Hi,
im struggling to locate the focused entry
the focus_get() only tells me it's an entry not which one
is there a way to locate the exact entry that's focused?
Thank you!!!
There's a bunch of blogs on this, to get the list I googled 'tkinter, determine which widget has current focus'

In my book Tkinter is annoying for anything than the most simplistic application, I only use it for a quick GUI.
If I am writing anything serious, I use wxpython (phoenix version)
but also good are Kivy, and Qt5

if you're just starting your application, you may want to consider one of these.

On the wxpython side, here's an example of just how simple an app can be: https://python-forum.io/Thread-Perfectly...t=wxpython
ive nearly finished lol
just optimising but thank you
Please share your solution with others. Thank You.
the solution i have now is very limited to my program, I simply bind every widgets with '<Return>' as:
def refresh(event):
    '''
    function here
    '''

widget1.bind('<Return>',refresh)
widget2.bind('<Return>',refresh)
#......
window.mainloop()
so that after i input the value i need to press entre to run the function i need.
I don't know if this will help but the entry has validatecommand here's a link to a stacked thread https://stackoverflow.com/questions/4140...in-tkinter in the first example there was a event focusin and focusout ...