Pysimplegui: [Question] How to read input text in the same way Input() does?

Created on 9 Dec 2019  路  2Comments  路  Source: PySimpleGUI/PySimpleGUI

Question

Ubuntu

3

PySimpleGUI latest

Your Experience Levels In Months or Years

___4 years____ Python programming experience
____7 years___ Programming experience overall
____Yes______ Have used another Python GUI Framework (tkiner, Qt, etc) previously (yes/no is fine)?

You have completed these steps:

  • [x ] Read instructions on how to file an Issue
  • [x ] Searched through main docs http://www.PySimpleGUI.org for your problem
  • [x ] Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • [x ] Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com
  • [x ] Note that there are also Demo Programs under each port on GitHub
  • [x ] Run your program outside of your debugger (from a command line)
  • [x ] Searched through Issues (open and closed) to see if already reported

I'm working with a barcode scanner which acts like a keyboard by typing a string of numbers followed by a return/enter keypress. When using Input(), this works fine. But I can't figure out how to do this with the InputText object. I don't even really need a text box at all.

And when I set the window to return keyboard events, it only returns the first number of the barcode. Is there a different object I can use?

Most helpful comment

PySimpleGUI is a GUI so there's going to be a window for example. If you want a window where the user enters text, then returning keyboard events should be returning every keypress that's made while the window has focus.

This program does not have an input box. You receive an event for every character that is typed. You can add those characters as they come in to a string to build up an entire input string.

When it detects the return key, it prints out the value you entered

import PySimpleGUI as sg

sg.change_look_and_feel('Dark Blue 3')

layout = [  [sg.Text('Type a string followed by return key')]]

window = sg.Window('Window Title', layout, return_keyboard_events=True)

my_string = ''
while True:             # Event Loop
    event, values = window.read()
    if event in (None, 'Exit'):
        break
    if event == '\r':
        print(f'You entered: {my_string}')
        my_string = ''
    else:
        my_string += event
window.close()

All 2 comments

PySimpleGUI is a GUI so there's going to be a window for example. If you want a window where the user enters text, then returning keyboard events should be returning every keypress that's made while the window has focus.

This program does not have an input box. You receive an event for every character that is typed. You can add those characters as they come in to a string to build up an entire input string.

When it detects the return key, it prints out the value you entered

import PySimpleGUI as sg

sg.change_look_and_feel('Dark Blue 3')

layout = [  [sg.Text('Type a string followed by return key')]]

window = sg.Window('Window Title', layout, return_keyboard_events=True)

my_string = ''
while True:             # Event Loop
    event, values = window.read()
    if event in (None, 'Exit'):
        break
    if event == '\r':
        print(f'You entered: {my_string}')
        my_string = ''
    else:
        my_string += event
window.close()

I think the demo program above should get you what you're looking for. If not, re-open the Issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xuguojun168 picture xuguojun168  路  3Comments

OndoyManing picture OndoyManing  路  4Comments

mozesa picture mozesa  路  5Comments

flowerbug picture flowerbug  路  4Comments

scmanjarrez picture scmanjarrez  路  5Comments