Merge pull request #2053 from PySimpleGUI/Dev-latest

Refreshed Menu Demo
This commit is contained in:
PySimpleGUI 2019-10-07 16:37:20 -04:00 committed by GitHub
commit ccc3021268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 23 deletions

View File

@ -1,29 +1,25 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import PySimpleGUI as sg
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" """
Demonstration of MENUS! Demonstration of MENUS!
How do menus work? Like buttons is how. How do menus work? Like buttons is how.
Check out the variable menu_def for a hint on how to Check out the variable menu_def for a hint on how to
define menus define menus
""" """
def SecondForm(): def second_window():
layout = [[sg.Text('The second form is small \nHere to show that opening a window using a window works')], layout = [[sg.Text('The second form is small \nHere to show that opening a window using a window works')],
[sg.OK()]] [sg.OK()]]
window = sg.Window('Second Form').Layout(layout) window = sg.Window('Second Form', layout)
b, v = window.Read() event, values = window.read()
window.close()
def test_menus():
def TestMenus(): sg.change_look_and_feel('LightGreen')
sg.set_options(element_padding=(0, 0))
sg.ChangeLookAndFeel('LightGreen')
sg.SetOptions(element_padding=(0, 0))
# ------ Menu Definition ------ # # ------ Menu Definition ------ #
menu_def = [['&File', ['&Open', '&Save', '&Properties', 'E&xit' ]], menu_def = [['&File', ['&Open', '&Save', '&Properties', 'E&xit' ]],
@ -33,32 +29,32 @@ def TestMenus():
# ------ GUI Defintion ------ # # ------ GUI Defintion ------ #
layout = [ layout = [
[sg.Menu(menu_def, tearoff=False, pad=(20,1))], [sg.Menu(menu_def, tearoff=False, pad=(20,1))],
[sg.Output(size=(60,20))], [sg.Output(size=(60,20))],
[sg.Text('Status Bar', relief=sg.RELIEF_SUNKEN, size=(55,1), pad=(0,3),key='_status_')]
] ]
window = sg.Window("Windows-like program", window = sg.Window("Windows-like program",
layout,
default_element_size=(12, 1), default_element_size=(12, 1),
auto_size_text=False, auto_size_text=False,
auto_size_buttons=False, auto_size_buttons=False,
default_button_element_size=(12, 1)).Layout(layout) default_button_element_size=(12, 1))
# ------ Loop & Process button menu choices ------ # # ------ Loop & Process button menu choices ------ #
while True: while True:
event, values = window.Read() event, values = window.read()
if event is None or event == 'Exit': if event is None or event == 'Exit':
return return
print('Event = ', event) print('Event = ', event)
# ------ Process menu choices ------ # # ------ Process menu choices ------ #
if event == 'About...': if event == 'About...':
window.Disappear() window.disappear()
sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...', grab_anywhere=True) sg.popup('About this program','Version 1.0', 'PySimpleGUI rocks...', grab_anywhere=True)
window.Reappear() window.reappear()
elif event == 'Open': elif event == 'Open':
filename = sg.PopupGetFile('file to open', no_window=True) filename = sg.popup_get_file('file to open', no_window=True)
print(filename) print(filename)
elif event == 'Properties': elif event == 'Properties':
SecondForm() second_window()
TestMenus() test_menus()