vyne121 / istqbPreparation

7 stars 0 forks source link

Very nice! Is this your first PySimpleGUI program? #1

Closed PySimpleGUI closed 1 week ago

PySimpleGUI commented 2 years ago

Thanks for sharing your program! Would be great to see a screenshot in your readme. I love seeing what people make.

I've been pushing a concept that I totally undersold when writing the documentation, examples, cookbook for PySimpleGUI. That concept is using tuples as keys,

They make it possible to do no parsing at all where using strings requires a lot of parsing.

For example, a key of "ITEM_1" needs to be parsed to get the ITEM and the 1 part.

If the key was named ("ITEM", 1) then there need to be no parsing. If event[0] == "ITEM" then you know it was one of those thigs being numbed and event[1] tells you which.

The same holds true for values lookups. To get 6 checkboxes that are numbered you could write:

import PySimpleGUI as sg

layout = [  [sg.Checkbox(i, key=('-CB-', i)) for i in range(6)],
            [sg.Button('Go'), sg.Button('Exit')]  ]

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

while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == 'Go':
        sg.Print('Checkboxes =')
        for i in range(6):
            sg.Print(values[('-CB-', i)])
window.close()

image

Also.... just an FYIU as you may not have seen it, but PySimpleGUI provides a simplified interface to JSON file you might like.


The bigger message in all this is post a screeenshot! We all like seeing pictures. And to keep building stuff. you're doing great

image

vyne121 commented 2 years ago

Wow! Thank you for reaching out! Yes, this is my first attempt on PySimpleGUI. Appreciate the suggestion, I will try to apply it to my code.

PySimpleGUI commented 2 years ago

I like the enthusiasm!

Here's some code from one of the Demo Programs... but I fear it's actually not a good example to show you

import PySimpleGUI as sg

questions = ('Managing your day-to-day life', 'Coping with problems in your life?', 'Concentrating?',
             'Get along with people in your family?', 'Get along with people outside your family?',
             'Get along well in social situations?', 'Feel close to another person',
             'Feel like you had someone to turn to if you needed help?', 'Felt confident in yourself?')

# These are the question # and the question text
layout = [[[sg.Text(qnum + 1, size=(2, 2)), sg.Text(q, size=(30, 2))] +
           # finally add an OK button at the very bottom by using the '+' operator
           [sg.Radio('', group_id=qnum, size=(7, 2), key=(qnum, col)) for col in range(5)]] for qnum, q in enumerate(questions)] + [[sg.OK()]]

window = sg.Window('Questionnaire', layout)

event, values = window.read(close=True)

print(values)

It's too "clever".

The important thing is that tuples can be really good for keys. There is no "right" way to use them in this way. Lots of possibilities.

I'm really impressed this was your first GUI! GREAT job!

image