Python Forum
[PySimpleGUI] Tutorial - Name, Address, Phone GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PySimpleGUI] Tutorial - Name, Address, Phone GUI
#27
(Aug-08-2018, 11:12 AM)jfong Wrote: If values is a dictionary, you can write (suppose 'address' is a key):

print(values['address'])

I think I understood your point. I was trying to mitigate with existing capabilities.

How would you suggest that the 'address' dictionary entry be created? How does the user tell PySimpleGUI that the second field is 'address'?

Something like this?
g.InputText(key='address')
That adds a bit more code to every form.

But, perhaps I could do a hybrid approach where BOTH types of return values are available. The "simplified" way and the more elegant way.

Every input field would have a new keyword, "key" that can be added if desired. That will enable that field to be addressed in the return values as a dictionary lookup. I'll add a new flag already to the "read form" calls so that the return values are either a list or a dictionary.

Thanks for the suggestions... keep 'em coming!

How does something like this look to you?
import PySimpleGUI as sg

form = sg.FlexForm('Simple data entry form', use_dictionary=True)  # begin with a blank form

layout = [
          [sg.Text('Please enter your Name, Address, Phone')],
          [sg.Text('Name', size=(15, 1)), sg.InputText('1', key='name')],
          [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['name'], values['address'], values['phone'])

print(values)
The code is pretty much done.
You set the indicator that you're working with dictionary return values when you create the form. Keys for each input field are set when the form is laid out as shown in the sample.

If it looks good, I'll check the code in shortly for you to try.

DONE!

Return values as a dictionary feature officially done and posted to GitHub. It'll be part of release 2.8 that I'll post to PyPI after everything has been tested more. Afraid of breaking something at the moment.

There is a new demo, Demo_Dictionary.py, that contains above code as a template.
Reply


Messages In This Thread
RE: [PySimpleGUI] Tutorial - Name, Address, Phone GUI - by PySimpleGUI - Aug-08-2018, 02:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PySimpleGUI Try Except jamesaarr 1 1,978 Nov-18-2021, 02:02 PM
Last Post: jamesaarr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020