Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter focus
#1
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!!!
Reply
#2
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
Reply
#3
ive nearly finished lol
just optimising but thank you
Reply
#4
Please share your solution with others. Thank You.
Reply
#5
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.
Reply
#6
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 ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to disable focus on Frame in Tkinter? szafranji 1 1,249 May-13-2020, 10:45 PM
Last Post: DT2000
  QComboBox doesn't display selection as long as it has not lost the focus Meaulnes 3 855 May-07-2020, 03:42 PM
Last Post: Meaulnes
  [Tkinter] Resetting scale value back to 0 after the slider loses focus lwhistler 3 4,374 Mar-07-2017, 10:01 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020