0
votes

Is it possible to use input in PySimpleGUI to behave like a button event?

I would like to read a scancod (44 characters) in Input, after the automatic reception enters (Return Key), and add this code to a listbox. I was looking for a documentation, but I can't adapt myself '' 'window = sg.Window("Keyboard Test", layout, return_keyboard_events = True, use_default_focus = False)' '' Give me an example, please. Thanks

1

1 Answers

1
votes

You can bind "<Return>" key to your input element, then do something in event loop.

import PySimpleGUI as sg

layout = [[sg.Input(key='INPUT')]]
window = sg.Window("Title", layout, finalize=True)
entry = window['INPUT']
entry.bind("<Return>", "_RETURN")

while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    elif event == "INPUT_RETURN":
        print(f"Input: {values['INPUT']}")

window.close()