Reputation: 23
I'm making a program on the Raspberry Pi with a touchscreen display. I'm using Python Tkinter that has two entry widgets and one on screen keypad. I want to use the same keypad for entering data on both entry widgets.
Can anyone tell me how can i check if an entry is selected? Similar like clicking on the Entry using the mouse and the cursor appears. How can I know that in Python Tkinter?
Thank you.
Upvotes: 1
Views: 2665
Reputation: 386010
There is always a widget with the keyboard focus. You can query that with the focus_get
method of the root window. It will return whatever widget has keyboard focus. That is the window that should receive input from your keypad.
Upvotes: 2
Reputation: 575
You can use events and bindigs to catch FocusIn events for your entries.
entry1 = Entry(root)
entry2 = Entry(root)
def callback_entry1_focus(event):
print 'entry1 focus in'
def callback_entry2_focus(event):
print 'entry2 focus in'
entry1.bind("<FocusIn>", callback_entry1_focus)
entry2.bind("<FocusIn>", callback_entry2_focus)
Upvotes: 1