0

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 Answer 1

2

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()
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Jason Yang First of all, I would like to say thank you so much!!! Sencondly it's a pleasure answed by someone who is one of the PySimpleGUI contributors. Anyway this solve my question, thanks I'm looking the Documentation (pysimplegui.readthedocs.io/en/latest/call%20reference/#window), trying to understand what mean >> finalize << Window parameter. I'm still a bit confused. Type: bool, Name: finalize, Meaning: If True then the Finalize method will be called. Use this rather than chaining .Finalize for cleaner code
Before window finalized, PySimpleGUI just configure everything about layout or settings. Startup tkinter only when sg.Window with option finalize=True, window.finalize() or window.read(). All of them will do the samething to finalize window by tkinter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.