Aug-10-2018, 01:31 AM
(Aug-09-2018, 03:42 PM)PySimpleGUI Wrote: A change to how dictionaries work.
You no longer need to specify when creating the form that it should return a dictionary. If ANY element in the form that has a key specified will cause all of the elements to return a dictionary entry.
If one element has a key and others do not, then the other fields are simply numbered starting at 0. That number is used as the key for the field.
For example:
import PySimpleGUI as sg layout = [ [sg.Text('Please enter your Name, Address, Phone')], [sg.Text('Name', size=(15, 1)), sg.InputText('1')], [sg.Text('Address', size=(15, 1)), sg.InputText('2', key='address')], [sg.Text('Phone', size=(15, 1)), sg.InputText('3', key='phone')], [sg.Submit(), sg.Cancel()] ] button, values = form.LayoutAndRead(layout) sg.MsgBox(button, values, values[0], values['address'], values['phone'])Two of the Input fields have keys but the first one doesn't. That means that the first field will be returned with a dictionary key of 0.
Inspired by your new change, allow me to push it one step further.
If none of the elements has a key, then all fields are simply numbered starting at 0.
This means that values is always returned as a dictionary, get rid of the confusion between list and dictionary. With this change, for those already written scripts which treat values as a list, the only required modification is where items were accessed through unpack, such as:
name, address, phone = values
modified to
name, address, phone = values.values()
If item was accessed by index, then no change at all.
name = values[0]
it's valid on both list and dictionary.