1. ################
  2. # the code #
  3. ################
  4. import PySimpleGUI as sg
  5. # ----------- Create the 3 layouts this Window will display -----------
  6. layout1 = [[sg.Text('This is layout 1 - It is all Checkboxes')],
  7. *[[sg.CB(f'Checkbox {i}')] for i in range(5)]]
  8. layout2 = [[sg.Text('This is layout 2')],
  9. [sg.Input(key='-IN-')],
  10. [sg.Input(key='-IN2-')]]
  11. layout3 = [[sg.Text('This is layout 3 - It is all Radio Buttons')],
  12. *[[sg.R(f'Radio {i}', 1)] for i in range(8)]]
  13. # ----------- Create actual layout using Columns and a row of Buttons
  14. layout = [[sg.Column(layout1, key='-COL1-'), sg.Column(layout2, visible=False, key='-COL2-'), sg.Column(layout3, visible=False, key='-COL3-')],
  15. [sg.Button('Cycle Layout'), sg.Button('1'), sg.Button('2'), sg.Button('3'), sg.Button('Exit')]]
  16. window = sg.Window('Swapping the contents of a window', layout)
  17. layout = 1 # The currently visible layout
  18. while True:
  19. event, values = window.read()
  20. print(event, values)
  21. if event in (None, 'Exit'):
  22. break
  23. if event == 'Cycle Layout':
  24. window[f'-COL{layout}-'].update(visible=False)
  25. layout = layout + 1 if layout < 3 else 1
  26. window[f'-COL{layout}-'].update(visible=True)
  27. elif event in '123':
  28. window[f'-COL{layout}-'].update(visible=False)
  29. layout = int(event)
  30. window[f'-COL{layout}-'].update(visible=True)
  31. window.close()