![]() |
Tkinter focus - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Tkinter focus (/thread-24877.html) |
Tkinter focus - catlessness - Mar-08-2020 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!!! RE: Tkinter focus - Larz60+ - Mar-08-2020 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-proportioned-3-frame-wxpython-application-template?highlight=wxpython RE: Tkinter focus - catlessness - Mar-09-2020 ive nearly finished lol just optimising but thank you RE: Tkinter focus - Larz60+ - Mar-09-2020 Please share your solution with others. Thank You. RE: Tkinter focus - catlessness - Apr-02-2020 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. RE: Tkinter focus - joe_momma - Apr-03-2020 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/4140437/interactively-validating-entry-widget-content-in-tkinter in the first example there was a event focusin and focusout ... |