2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
2018-11-20 16:48:37 +00:00
|
|
|
"""
|
2020-07-30 12:13:54 +00:00
|
|
|
Multiple Window Design Pattern
|
|
|
|
|
2020-08-07 10:48:14 +00:00
|
|
|
Two windows - both remain active and visible
|
2020-07-30 12:13:54 +00:00
|
|
|
Window 1 launches Window 2
|
|
|
|
Window 1 remains visible and active while Window 2 is active
|
|
|
|
Closing Window 1 exits application
|
|
|
|
|
2020-08-07 10:48:14 +00:00
|
|
|
Copyright 2020 PySimpleGUI.org
|
2018-11-20 16:48:37 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2020-07-30 12:13:54 +00:00
|
|
|
def make_window1():
|
|
|
|
layout = [[ sg.Text('Window 1'),],
|
|
|
|
[sg.Input(enable_events=True, k='-IN-')],
|
|
|
|
[sg.Text(size=(20,1), k='-OUTPUT-')],
|
|
|
|
[sg.Button('Launch 2'), sg.Button('Exit')]]
|
2018-11-20 16:48:37 +00:00
|
|
|
|
2020-07-30 12:13:54 +00:00
|
|
|
return sg.Window('Window 1', layout, finalize=True)
|
2019-12-24 23:52:47 +00:00
|
|
|
|
2018-11-20 16:48:37 +00:00
|
|
|
|
2020-07-30 12:13:54 +00:00
|
|
|
def make_window2():
|
|
|
|
layout = [[sg.Text('Window 2')],
|
|
|
|
[sg.Button('Exit')]]
|
2018-11-20 16:48:37 +00:00
|
|
|
|
2020-07-30 12:13:54 +00:00
|
|
|
return sg.Window('Window 2', layout, finalize=True)
|
2018-11-20 16:48:37 +00:00
|
|
|
|
2020-07-30 12:13:54 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
window1, window2 = make_window1(), None
|
|
|
|
while True:
|
|
|
|
window, event, values = sg.read_all_windows()
|
|
|
|
if window == window1 and event in (sg.WIN_CLOSED, 'Exit'):
|
|
|
|
break
|
|
|
|
# Window 1 stuff
|
|
|
|
if event == '-IN-':
|
|
|
|
window['-OUTPUT-'].update(values['-IN-'])
|
|
|
|
elif event == 'Launch 2' and not window2:
|
|
|
|
window2 = make_window2()
|
|
|
|
|
|
|
|
# Window 2 stuff
|
|
|
|
if window == window2 and event in(sg.WIN_CLOSED, 'Exit'):
|
2019-10-23 20:10:03 +00:00
|
|
|
window2.close()
|
2020-07-30 12:13:54 +00:00
|
|
|
window2 = None
|
|
|
|
|
|
|
|
window1.close()
|
2020-08-07 10:48:14 +00:00
|
|
|
if window2 is not None:
|
|
|
|
window2.close()
|
2020-07-30 12:13:54 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
|
2020-07-30 12:13:54 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|