External Exam Download Resources Web Applications Games Recycle Bin

Colours, Multiforms

PSG_colours.py

import PySimpleGUI as PSG
PSG.SetOptions(
    background_color = "salmon",
    text_element_background_color = "plum",
    text_color = "white"
)

LAYOUT = [ [PSG.Text("Some Text Here")] ]
FORM = PSG.FlexForm("")
FORM.Layout(LAYOUT)

button, value = FORM.Read()

multiple_forms.py

import PySimpleGUI as PSG

PRIMARY_LAYOUT = [ [PSG.ReadFormButton("CLOSE PRIMARY")],
                    [PSG.ReadFormButton("OPEN SECONDARY")] ]

SECONDARY_LAYOUT = [ [PSG.ReadFormButton("SAVE AND CLOSE SECONDARY")] ]

PRIMARY = PSG.FlexForm("")
PRIMARY.Layout(PRIMARY_LAYOUT)

while True:
    button, value = PRIMARY.Read()
    if button == "OPEN SECONDARY":
        SECONDARY = PSG.FlexForm("")
        button, value = SECONDARY.LayoutAndRead(SECONDARY_LAYOUT)
        #-----------------------------------------
        #GET WHATEVER YOU NEED FROM SECONDARY HERE
        #-----------------------------------------
        SECONDARY.CloseNonBlockingForm()
    if button == "CLOSE PRIMARY":
        PRIMARY.CloseNonBlockingForm()
        break

multiple_forms_example.py

import PySimpleGUI as PSG

PRIMARY_LAYOUT = [ [PSG.ReadFormButton("CLOSE PRIMARY")],
                    [PSG.ReadFormButton("OPEN SECONDARY")] ]

SECONDARY_LAYOUT = [ [PSG.InputText("Gday Mate", key="Hi")],
                      [PSG.ReadFormButton("SAVE AND CLOSE SECONDARY")] ]

PRIMARY = PSG.FlexForm("")
PRIMARY.Layout(PRIMARY_LAYOUT)

while True:
    button, value = PRIMARY.Read()
    if button == "OPEN SECONDARY":
        SECONDARY = PSG.FlexForm("")
        button, value = SECONDARY.LayoutAndRead(SECONDARY_LAYOUT)
        print(value["Hi"])
        SECONDARY.CloseNonBlockingForm()
    if button == "CLOSE PRIMARY":
        PRIMARY.CloseNonBlockingForm()
        break

Using the cards, coins or dice resources available on this website:

  1. Can you create a Heads or Tails coin flipper?

  2. Can you create a random Card Draw app?