check which entry is focused (Python) check which entry is focused (Python) tkinter tkinter

check which entry is focused (Python)


You can call keyboardFrame.focus_get() to get the window object that has the focus.


What you want is to remember the last Entry that had focus.Because pressing a button will give the focus to the button.

hasFocus = Nonedef currentEntry(myEntry):    global hasFocus     hasFocus = myEntryusername.bind("<FocusIn>", lambda myEvent: currentEntry(username)) # do the same for the other entries

Then use hasFocus in select.

NB: you probably wish to add if inputFocus != None: in select because at the beginning, there is no selected Entry.