1 Shot Window - Simple Data Entry - Return Values - Auto Numbered
Remember how keys are key to understanding PySimpleGUI elements? Well, they are, so now you know.
If you do not specify a key and the element is an input element, a key will be provided for you in the form of an integer, starting numbering with zero. If you don't specify any keys, it will appear as if the values returned to you are being returned as a list because the keys are sequential ints.
This example has no keys specified. The 3 input fields will have keys 0, 1, 2. Your first input element will be accessed as values[0]
, just like a list would look.
import PySimpleGUI as sg
sg.theme('Topanga') # Add some color to the window
# Very basic window. Return values using auto numbered keys
layout = [
[sg.Text('Please enter your Name, Address, Phone')],
[sg.Text('Name', size=(15, 1)), sg.InputText()],
[sg.Text('Address', size=(15, 1)), sg.InputText()],
[sg.Text('Phone', size=(15, 1)), sg.InputText()],
[sg.Submit(), sg.Cancel()]
]
window = sg.Window('Simple data entry window', layout)
event, values = window.read()
window.close()
print(event, values[0], values[1], values[2]) # the input data looks like a simple list when auto numbered