Removed last of Context Manager from Popups. Added Underscore to Menu Examples, Updated Templates, Better Popup examples

This commit is contained in:
MikeTheWatchGuy 2018-09-29 13:48:48 -04:00
parent 96635ef5a2
commit d1773e6447
5 changed files with 55 additions and 46 deletions

View File

@ -8,9 +8,9 @@ else:
sg.ChangeLookAndFeel('GreenTan') sg.ChangeLookAndFeel('GreenTan')
# ------ Menu Definition ------ # # ------ Menu Definition ------ #
menu_def = [['File', ['Open', 'Save', 'Exit', 'Properties']], menu_def = [['&File', ['&Open', '&Save', 'E&xit', 'Properties']],
['Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ], ['&Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['Help', 'About...'], ] ['&Help', '&About...'], ]
# ------ Column Definition ------ # # ------ Column Definition ------ #
column1 = [[sg.Text('Column 1', background_color='#F7F3EC', justification='center', size=(10, 1))], column1 = [[sg.Text('Column 1', background_color='#F7F3EC', justification='center', size=(10, 1))],

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
import PySimpleGUI as sg import PySimpleGUI_mod as sg
else: else:
import PySimpleGUI27 as sg import PySimpleGUI27 as sg
""" """
@ -26,9 +26,10 @@ def TestMenus():
sg.SetOptions(element_padding=(0, 0)) sg.SetOptions(element_padding=(0, 0))
# ------ Menu Definition ------ # # ------ Menu Definition ------ #
menu_def = [['File', ['O_&pen', 'Save', '---', 'Properties']], menu_def = [['&File', ['&Open', '&Save', '---', 'Properties', 'E&xit' ]],
['Edit', ['Paste', ['Special', 'Normal',], 'Undo'],], ['&Edit', ['Paste', ['Special', 'Normal',], 'Undo'],],
['Help', 'About...'],] [''
'&Help', '&About...'],]
# ------ GUI Defintion ------ # # ------ GUI Defintion ------ #
layout = [ layout = [
@ -48,9 +49,9 @@ def TestMenus():
print('Button = ', button) print('Button = ', button)
# ------ Process menu choices ------ # # ------ Process menu choices ------ #
if button == 'About...': if button == 'About...':
window.Disable() window.Hide()
sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...') sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...', grab_anywhere=True)
window.Enable() window.UnHide()
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)

View File

@ -6,18 +6,23 @@ else:
import PySimpleGUI27 as sg import PySimpleGUI27 as sg
# Here, have some windows on me.... # Here, have some windows on me....
[sg.PopupNoWait(location=(10*x,0)) for x in range(10)] [sg.PopupNoWait(location=(500+100*x,500)) for x in range(10)]
print (sg.PopupYesNo('Yes No')) answer = sg.PopupYesNo('Do not worry about all those open windows... they will disappear at the end', 'Are you OK with that?')
print(sg.PopupGetText('Get text', location=(1000,200))) if answer == 'No':
print(sg.PopupGetFile('Get file')) sg.PopupCancel('OK, we will destroy those windows as soon as you close this window')
print(sg.PopupGetFolder('Get folder')) sys.exit()
sg.PopupNonBlocking('Your answer was',answer, location=(1000,600))
text = sg.PopupGetText('This is a call to PopopGetText', location=(1000,200))
sg.PopupGetFile('Get file')
sg.PopupGetFolder('Get folder')
sg.Popup('Simple popup') sg.Popup('Simple popup')
sg.PopupNonBlocking('Non Blocking', location=(500,500))
sg.PopupNoTitlebar('No titlebar') sg.PopupNoTitlebar('No titlebar')
sg.PopupNoBorder('No border') sg.PopupNoBorder('No border')
sg.PopupNoFrame('No frame') sg.PopupNoFrame('No frame')

View File

@ -10,7 +10,8 @@ if sys.version_info[0] >= 3:
else: else:
import PySimpleGUI27 as sg import PySimpleGUI27 as sg
layout = [[ sg.Text('My layout') ]] layout = [[ sg.Text('My layout') ],
[ sg.Button('Next Window')]]
window = sg.Window('My window').Layout(layout) window = sg.Window('My window').Layout(layout)
button, value = window.Read() button, value = window.Read()
@ -26,7 +27,8 @@ if sys.version_info[0] >= 3:
else: else:
import PySimpleGUI27 as sg import PySimpleGUI27 as sg
layout = [[ sg.Text('My layout') ]] layout = [[ sg.Text('My layout') ],
[ sg.RButton('Read The Window')]]
window = sg.Window('My new window').Layout(layout) window = sg.Window('My new window').Layout(layout)
@ -34,3 +36,4 @@ while True: # Event Loop
button, value = window.Read() button, value = window.Read()
if button is None: if button is None:
break break
print(button, value)

View File

@ -3873,7 +3873,7 @@ def ScrolledTextBox(*args, button_color=None, yes_no=False, auto_close=False, au
if not args: return if not args: return
width, height = size width, height = size
width = width if width else MESSAGE_BOX_LINE_WIDTH width = width if width else MESSAGE_BOX_LINE_WIDTH
with Window(args[0], auto_size_text=True, button_color=button_color, auto_close=auto_close, auto_close_duration=auto_close_duration) as form: form = Window(args[0], auto_size_text=True, button_color=button_color, auto_close=auto_close, auto_close_duration=auto_close_duration)
max_line_total, max_line_width, total_lines, height_computed = 0,0,0,0 max_line_total, max_line_width, total_lines, height_computed = 0,0,0,0
complete_output = '' complete_output = ''
for message in args: for message in args:
@ -3899,7 +3899,7 @@ def ScrolledTextBox(*args, button_color=None, yes_no=False, auto_close=False, au
button, values = form.Read() button, values = form.Read()
return button return button
else: else:
form.AddRow(Text('', size=(pad, 1), auto_size_text=False), SimpleButton('OK', size=(5, 1), button_color=button_color)) form.AddRow(Text('', size=(pad, 1), auto_size_text=False), Button('OK', size=(5, 1), button_color=button_color))
button, values = form.Read() button, values = form.Read()
return button return button