import PySimpleGUI as sg
layout = [[sg.Button("OK1", key='1', bind_return_key=True)],
[sg.Button("OK2", key='2', bind_return_key=True)],
[sg.Button("OK3", key='3', bind_return_key=True)]]
window = sg.Window("Keyboard Test", return_keyboard_events=True).Layout(layout)
while True:
event, values = window.Read()
print(event)
if event == None:
break
When I run the above code and perform mouse click operation, I get the output as following that is as expected,
clicking on OK1 Button print in the console as: 1
clicking on OK2 Button print in the console as: 2
clicking on OK3 Button print in the console as: 3
But, when I perform keyboard event means, I visit on the button through tab key of keyboard and press Enter on that Button via keyboard it return the same key on all these three button,
Visit on these button one by one via tab key and then press Enter on each I get the result as,
Press Enter on OK1 Button print in the console as: 1
Press Enter on OK2 Button print in the console as: 1
Press Enter on OK3 Button print in the console as: 1
That is not expected output. What I want it should also print their own key same as mouse click event.
What is my intention:
When user press Enter button over OK1, It should print('Hello, OK1 pressed.')
When user press Enter button over OK2, It should print('Hello, OK2 pressed.')
When user press Enter button over OK3, It should print('Hello, OK3 pressed.')
When user click on OK1, It should print('Hello, OK1 pressed.')
When user click on OK2, It should print('Hello, OK2 pressed.')
When user click on OK3, It should print('Hello, OK3 pressed.')
How to achieve this?