2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-11-20 16:48:37 +00:00
|
|
|
"""
|
2020-07-27 10:58:17 +00:00
|
|
|
Demo - 2 simultaneous windows using read_all_window
|
|
|
|
|
|
|
|
Window 1 launches window 2
|
|
|
|
BOTH remain active in parallel
|
|
|
|
|
|
|
|
Both windows have buttons to launch popups. The popups are "modal" and thus no other windows will be active
|
|
|
|
|
|
|
|
Copyright 2020 PySimpleGUI.org
|
2018-11-20 16:48:37 +00:00
|
|
|
"""
|
|
|
|
|
2020-07-27 10:58:17 +00:00
|
|
|
def make_win1():
|
|
|
|
layout = [[sg.Text('This is the FIRST WINDOW'), sg.Text(' ', k='-OUTPUT-')],
|
2020-07-30 12:13:54 +00:00
|
|
|
[sg.Text('Click Popup anytime to see a modal popup')],
|
2020-07-27 10:58:17 +00:00
|
|
|
[sg.Button('Launch 2nd Window'), sg.Button('Popup'), sg.Button('Exit')]]
|
|
|
|
return sg.Window('Window Title', layout, location=(800,600), finalize=True)
|
|
|
|
|
|
|
|
|
|
|
|
def make_win2():
|
|
|
|
layout = [[sg.Text('The second window')],
|
2020-07-30 12:13:54 +00:00
|
|
|
[sg.Input(key='-IN-', enable_events=True)],
|
2020-07-27 10:58:17 +00:00
|
|
|
[sg.Text(size=(25,1), k='-OUTPUT-')],
|
2020-07-30 12:13:54 +00:00
|
|
|
[sg.Button('Erase'), sg.Button('Popup'), sg.Button('Exit')]]
|
2020-07-27 10:58:17 +00:00
|
|
|
return sg.Window('Second Window', layout, finalize=True)
|
|
|
|
|
|
|
|
window1, window2 = make_win1(), None # start off with 1 window open
|
|
|
|
|
2018-11-20 16:48:37 +00:00
|
|
|
while True: # Event Loop
|
2020-07-27 10:58:17 +00:00
|
|
|
window, event, values = sg.read_all_windows()
|
|
|
|
if event == sg.WIN_CLOSED or event == 'Exit':
|
|
|
|
window.close()
|
|
|
|
if window == window2: # if closing win 2, mark as closed
|
|
|
|
window2 = None
|
|
|
|
elif window == window1: # if closing win 1, exit program
|
|
|
|
break
|
2018-11-20 16:48:37 +00:00
|
|
|
elif event == 'Popup':
|
2019-10-23 20:10:03 +00:00
|
|
|
sg.popup('This is a BLOCKING popup','all windows remain inactive while popup active')
|
2020-07-27 10:58:17 +00:00
|
|
|
elif event == 'Launch 2nd Window' and not window2:
|
|
|
|
window2 = make_win2()
|
2020-07-30 12:13:54 +00:00
|
|
|
elif event == '-IN-':
|
2020-07-27 10:58:17 +00:00
|
|
|
window['-OUTPUT-'].update(f'You enetered {values["-IN-"]}')
|
2020-07-30 12:13:54 +00:00
|
|
|
elif event == 'Erase':
|
|
|
|
window['-OUTPUT-'].update('')
|
|
|
|
window['-IN-'].update('')
|
2019-10-23 20:10:03 +00:00
|
|
|
window.close()
|