Updated Menu demo
This commit is contained in:
parent
a56cdb9735
commit
40983fb873
|
@ -6,16 +6,27 @@ import PySimpleGUI as sg
|
||||||
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():
|
||||||
|
|
||||||
|
layout = [[sg.Text('The second form is small \nHere to show that opening a window using a window works')],
|
||||||
|
[sg.OK()]]
|
||||||
|
|
||||||
|
form = sg.FlexForm('Second Form')
|
||||||
|
b, v = form.LayoutAndRead(layout)
|
||||||
|
|
||||||
|
|
||||||
def TestMenus():
|
def TestMenus():
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
|
|
||||||
sg.ChangeLookAndFeel('LightGreen')
|
sg.ChangeLookAndFeel('LightGreen')
|
||||||
sg.SetOptions(element_padding=(0, 0))
|
sg.SetOptions(element_padding=(0, 0))
|
||||||
|
|
||||||
menu_def = [['File', ['Open', 'Save',]],
|
# ------ Menu Definition ------ #
|
||||||
|
menu_def = [['File', ['Open', 'Save', 'Properties']],
|
||||||
['Edit', ['Paste', ['Special', 'Normal',], 'Undo'],],
|
['Edit', ['Paste', ['Special', 'Normal',], 'Undo'],],
|
||||||
['Help', 'About...'],]
|
['Help', 'About...'],]
|
||||||
|
|
||||||
|
# ------ GUI Defintion ------ #
|
||||||
layout = [
|
layout = [
|
||||||
[sg.Menu(menu_def)],
|
[sg.Menu(menu_def)],
|
||||||
[sg.Output(size=(60,20))]
|
[sg.Output(size=(60,20))]
|
||||||
|
@ -24,19 +35,22 @@ def TestMenus():
|
||||||
form = sg.FlexForm("Windows-like program", default_element_size=(12, 1), auto_size_text=False, auto_size_buttons=False,
|
form = sg.FlexForm("Windows-like program", default_element_size=(12, 1), auto_size_text=False, auto_size_buttons=False,
|
||||||
default_button_element_size=(12, 1))
|
default_button_element_size=(12, 1))
|
||||||
form.Layout(layout)
|
form.Layout(layout)
|
||||||
form.ReadNonBlocking() # so the print message will show up... yes, a kludge
|
|
||||||
|
|
||||||
print('Give those menus a try!')
|
# ------ Loop & Process button menu choices ------ #
|
||||||
while True:
|
while True:
|
||||||
button, values = form.Read()
|
button, values = form.Read()
|
||||||
if button is None or button == 'Exit':
|
if button is None or button == 'Exit':
|
||||||
return
|
return
|
||||||
print('Button = ', button)
|
print('Button = ', button)
|
||||||
|
# ------ Process menu choices ------ #
|
||||||
if button == 'About...':
|
if button == 'About...':
|
||||||
sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...')
|
sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...')
|
||||||
elif button == 'Open':
|
elif button == 'Open':
|
||||||
filename = sg.PopupGetFile('file to open', no_window=True)
|
filename = sg.PopupGetFile('file to open', no_window=True)
|
||||||
print(filename)
|
print(filename)
|
||||||
|
elif button == 'Properties':
|
||||||
|
SecondForm()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TestMenus()
|
TestMenus()
|
Loading…
Reference in New Issue