Discovered OLD code! Was using ReadButton!

This commit is contained in:
PySimpleGUI 2019-09-20 16:59:15 -04:00
parent 1d4ca6696f
commit e5e1021516
16 changed files with 95 additions and 61 deletions

View File

@ -13,7 +13,7 @@ layout = [[sg.Text('Bar graphs using PySimpleGUI')],
[graph], [graph],
[sg.Button('OK')]] [sg.Button('OK')]]
window = sg.Window('Window Title').Layout(layout) window = sg.Window('Window Title', layout)
while True: while True:
event, values = window.Read() event, values = window.Read()
@ -26,3 +26,4 @@ while True:
graph.DrawRectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value), graph.DrawRectangle(top_left=(i * BAR_SPACING + EDGE_OFFSET, graph_value),
bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue') bottom_right=(i * BAR_SPACING + EDGE_OFFSET + BAR_WIDTH, 0), fill_color='blue')
graph.DrawText(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10)) graph.DrawText(text=graph_value, location=(i*BAR_SPACING+EDGE_OFFSET+25, graph_value+10))
window.Close()

View File

@ -19,7 +19,7 @@ def main():
sg.PopupCancel('Cancelled - No valid folder entered') sg.PopupCancel('Cancelled - No valid folder entered')
return return
try: try:
namesonly = [f for f in os.listdir(folder) if f.endswith('.png') or f.endswith('.ico')] namesonly = [f for f in os.listdir(folder) if f.endswith('.png') or f.endswith('.ico') or f.endswith('.gif')]
except: except:
sg.PopupCancel('Cancelled - No valid folder entered') sg.PopupCancel('Cancelled - No valid folder entered')
return return

View File

@ -17,10 +17,10 @@ layout = [[sg.T('User:', pad=((3, 0), 0)), sg.OptionMenu(values=('User 1', 'User
[sg.T('Customer:', pad=((3, 0), 0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)), [sg.T('Customer:', pad=((3, 0), 0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)),
sg.T('1', size=(8, 1))], sg.T('1', size=(8, 1))],
[sg.T('Notes:', pad=((3, 0), 0)), sg.In(size=(44, 1), background_color='white', text_color='black')], [sg.T('Notes:', pad=((3, 0), 0)), sg.In(size=(44, 1), background_color='white', text_color='black')],
[sg.ReadButton('Start', button_color=('white', 'black')), [sg.Button('Start', button_color=('white', 'black')),
sg.ReadButton('Stop', button_color=('gray50', 'black')), sg.Button('Stop', button_color=('gray50', 'black')),
sg.ReadButton('Reset', button_color=('white', '#9B0023')), sg.Button('Reset', button_color=('white', '#9B0023')),
sg.ReadButton('Submit', button_color=('gray60', 'springgreen4')), sg.Button('Submit', button_color=('gray60', 'springgreen4')),
sg.Button('Exit', button_color=('white', '#00406B'))]] sg.Button('Exit', button_color=('white', '#00406B'))]]
window = sg.Window("Borderless Window", window = sg.Window("Borderless Window",

View File

@ -11,14 +11,14 @@ if not sys.platform.startswith('win'):
import winsound import winsound
sg.ChangeLookAndFeel('Dark') # sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0,0)) # sg.SetOptions(element_padding=(0,0))
layout = [ layout = [
[sg.ReadButton('Start', button_color=('white', 'black'), key='start'), [sg.Button('Start', button_color=('white', 'black'), key='start'),
sg.ReadButton('Stop', button_color=('white', 'black'), key='stop'), sg.Button('Stop', button_color=('white', 'black'), key='stop'),
sg.ReadButton('Reset', button_color=('white', 'firebrick3'), key='reset'), sg.Button('Reset', button_color=('white', 'firebrick3'), key='reset'),
sg.ReadButton('Submit', button_color=('white', 'springgreen4'), key='submit')] sg.Button('Submit', button_color=('white', 'springgreen4'), key='submit')]
] ]
window = sg.Window("Button Click", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False, default_button_element_size=(12,1), use_default_focus=False).Layout(layout).Finalize() window = sg.Window("Button Click", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False, default_button_element_size=(12,1), use_default_focus=False).Layout(layout).Finalize()
@ -27,7 +27,7 @@ window.FindElement('submit').Update(disabled=True)
recording = have_data = False recording = have_data = False
while True: while True:
event, values = window.Read() event, values = window.Read(timeout=100)
if event is None: if event is None:
sys.exit(69) sys.exit(69)
winsound.PlaySound("ButtonClick.wav", 1) winsound.PlaySound("ButtonClick.wav", 1) if event != sg.TIMEOUT_KEY else None

View File

@ -16,10 +16,10 @@ sg.SetOptions(element_padding=(0,0))
layout = [[sg.T('User:', pad=((3,0),0)), sg.OptionMenu(values = ('User 1', 'User 2'), size=(20,1)), sg.T('0', size=(8,1))], layout = [[sg.T('User:', pad=((3,0),0)), sg.OptionMenu(values = ('User 1', 'User 2'), size=(20,1)), sg.T('0', size=(8,1))],
[sg.T('Customer:', pad=((3,0),0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20,1)), sg.T('1', size=(8,1))], [sg.T('Customer:', pad=((3,0),0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20,1)), sg.T('1', size=(8,1))],
[sg.T('Notes:', pad=((3,0),0)), sg.In(size=(44,1), background_color='white', text_color='black')], [sg.T('Notes:', pad=((3,0),0)), sg.In(size=(44,1), background_color='white', text_color='black')],
[sg.ReadButton('Start', button_color=('white', 'black'), key='_Start_'), [sg.Button('Start', button_color=('white', 'black'), key='_Start_'),
sg.ReadButton('Stop', button_color=('white', 'black'), key='_Stop_'), sg.Button('Stop', button_color=('white', 'black'), key='_Stop_'),
sg.ReadButton('Reset', button_color=('white', 'firebrick3'), key='_Reset_'), sg.Button('Reset', button_color=('white', 'firebrick3'), key='_Reset_'),
sg.ReadButton('Submit', button_color=('white', 'springgreen4'), key='_Submit_')]] sg.Button('Submit', button_color=('white', 'springgreen4'), key='_Submit_')]]
window = sg.Window("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False, window = sg.Window("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(12,1)).Layout(layout).Finalize() default_button_element_size=(12,1)).Layout(layout).Finalize()

View File

@ -7,7 +7,7 @@ else:
layout = [ layout = [
[sg.Canvas(size=(150, 150), background_color='red', key='canvas')], [sg.Canvas(size=(150, 150), background_color='red', key='canvas')],
[sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue')] [sg.T('Change circle color to:'), sg.Button('Red'), sg.Button('Blue')]
] ]
window = sg.Window('Canvas test').Layout(layout).Finalize() window = sg.Window('Canvas test').Layout(layout).Finalize()

View File

@ -23,7 +23,7 @@ def ChatBotWithHistory():
[sg.Output(size=(127, 30), font=('Helvetica 10'))], [sg.Output(size=(127, 30), font=('Helvetica 10'))],
[sg.T('Command History'), sg.T('', size=(20,3), key='history')], [sg.T('Command History'), sg.T('', size=(20,3), key='history')],
[sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False), [sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False),
sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]] sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]]
window = sg.Window('Chat window with history', default_element_size=(30, 2), font=('Helvetica',' 13'), default_button_element_size=(8,2), return_keyboard_events=True).Layout(layout) window = sg.Window('Chat window with history', default_element_size=(30, 2), font=('Helvetica',' 13'), default_button_element_size=(8,2), return_keyboard_events=True).Layout(layout)

View File

@ -35,10 +35,10 @@ def Launcher():
sg.SetOptions(element_padding=(0,0), button_element_size=(12,1), auto_size_buttons=False) sg.SetOptions(element_padding=(0,0), button_element_size=(12,1), auto_size_buttons=False)
layout = [[sg.Combo(values=namesonly, size=(35,30), key='demofile'), layout = [[sg.Combo(values=namesonly, size=(35,30), key='demofile'),
sg.ReadButton('Run', button_color=('white', '#00168B')), sg.Button('Run', button_color=('white', '#00168B')),
sg.ReadButton('Program 1'), sg.Button('Program 1'),
sg.ReadButton('Program 2'), sg.Button('Program 2'),
sg.ReadButton('Program 3', button_color=('white', '#35008B')), sg.Button('Program 3', button_color=('white', '#35008B')),
sg.Button('EXIT', button_color=('white','firebrick3'))], sg.Button('EXIT', button_color=('white','firebrick3'))],
[sg.T('', text_color='white', size=(50,1), key='output')]] [sg.T('', text_color='white', size=(50,1), key='output')]]

View File

@ -17,10 +17,10 @@ layout = [
[sg.Spin((1,2,3,4),1,disabled=True, key='spin'), sg.OptionMenu((1,2,3,4),disabled=True, key='option'), sg.Combo(values=(1,2,3,4),disabled=True,key='combo')], [sg.Spin((1,2,3,4),1,disabled=True, key='spin'), sg.OptionMenu((1,2,3,4),disabled=True, key='option'), sg.Combo(values=(1,2,3,4),disabled=True,key='combo')],
[sg.Multiline('Multiline', size=(20,3),disabled=True, key='multi')], [sg.Multiline('Multiline', size=(20,3),disabled=True, key='multi')],
[sg.Slider((1,10), size=(20,20), orientation='h', disabled=True, key='slider')], [sg.Slider((1,10), size=(20,20), orientation='h', disabled=True, key='slider')],
[sg.ReadButton('Enable', button_color=('white', 'black')), [sg.Button('Enable', button_color=('white', 'black')),
sg.ReadButton('Disable', button_color=('white', 'black')), sg.Button('Disable', button_color=('white', 'black')),
sg.ReadButton('Reset', button_color=('white', '#9B0023'), key='reset'), sg.Button('Reset', button_color=('white', '#9B0023'), key='reset'),
sg.ReadButton('Values', button_color=('white', 'springgreen4')), sg.Button('Values', button_color=('white', 'springgreen4')),
sg.Button('Exit', disabled=True, button_color=('white', '#00406B'), key='exit')]] sg.Button('Exit', disabled=True, button_color=('white', '#00406B'), key='exit')]]
window = sg.Window("Disable Elements Demo", default_element_size=(12, 1), text_justification='r', auto_size_text=False, window = sg.Window("Disable Elements Demo", default_element_size=(12, 1), text_justification='r', auto_size_text=False,

View File

@ -7,7 +7,7 @@ else:
import PySimpleGUI27 as sg import PySimpleGUI27 as sg
def Everything(): def Everything():
sg.ChangeLookAndFeel('BlueMono') sg.ChangeLookAndFeel('TanBlue')
column1 = [ column1 = [
[sg.Text('Column 1', background_color=sg.DEFAULT_BACKGROUND_COLOR, justification='center', size=(10, 1))], [sg.Text('Column 1', background_color=sg.DEFAULT_BACKGROUND_COLOR, justification='center', size=(10, 1))],
@ -37,8 +37,8 @@ def Everything():
[sg.Text('Choose A Folder', size=(35, 1))], [sg.Text('Choose A Folder', size=(35, 1))],
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'), [sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
sg.InputText('Default Folder', key='folder', do_not_clear=True), sg.FolderBrowse()], sg.InputText('Default Folder', key='folder', do_not_clear=True), sg.FolderBrowse()],
[sg.ReadButton('Exit'), [sg.Button('Exit'),
sg.Text(' ' * 40), sg.ReadButton('SaveSettings'), sg.ReadButton('LoadSettings')] sg.Text(' ' * 40), sg.Button('SaveSettings'), sg.Button('LoadSettings')]
] ]
window = sg.Window('Form Fill Demonstration', default_element_size=(40, 1), grab_anywhere=False) window = sg.Window('Form Fill Demonstration', default_element_size=(40, 1), grab_anywhere=False)

View File

@ -6,7 +6,7 @@ else:
import PySimpleGUI27 as sg import PySimpleGUI27 as sg
layout = [[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0,0), graph_top_right=(400, 400), background_color='red', key='graph')], layout = [[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0,0), graph_top_right=(400, 400), background_color='red', key='graph')],
[sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue'), sg.ReadButton('Move')]] [sg.T('Change circle color to:'), sg.Button('Red'), sg.Button('Blue'), sg.Button('Move')]]
window = sg.Window('Graph test').Layout(layout).Finalize() window = sg.Window('Graph test').Layout(layout).Finalize()

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 PySimpleGUIQt as sg
else: else:
import PySimpleGUI27 as sg import PySimpleGUI27 as sg
import subprocess import subprocess
@ -26,12 +26,12 @@ def HowDoI():
layout = [ layout = [
[sg.Text('Ask and your answer will appear here....', size=(40, 1))], [sg.Text('Ask and your answer will appear here....', size=(40, 1))],
[sg.Output(size=(127, 30), font=('Helvetica 10'))], [sg.Output(size=(120, 30), font=('Helvetica 10'))],
[ sg.Spin(values=(1, 2, 3, 4), initial_value=1, size=(2, 1), key='Num Answers', font='Helvetica 15'), [ sg.Spin(values=(1, 2, 3, 4), initial_value=1, size=(2, 1), key='Num Answers', font='Helvetica 15'),
sg.Text('Num Answers',font='Helvetica 15'), sg.Checkbox('Display Full Text', key='full text', font='Helvetica 15'), sg.Text('Num Answers',font='Helvetica 15'), sg.Checkbox('Display Full Text', key='full text', font='Helvetica 15'),
sg.T('Command History', font='Helvetica 15'), sg.T('', size=(40,3), text_color=sg.BLUES[0], key='history')], sg.T('Command History', font='Helvetica 15'), sg.T('', size=(40,3), text_color=sg.BLUES[0], key='history')],
[sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False), [sg.Multiline(size=(85, 5), enter_submits=True, key='query', do_not_clear=False),
sg.ReadButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.Button('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True),
sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))] sg.Button('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))]
] ]

View File

@ -77,7 +77,7 @@ col = [[filename_display_elem],
[image_elem]] [image_elem]]
col_files = [[sg.Listbox(values = fnames, change_submits=True, size=(60, 30), key='listbox')], col_files = [[sg.Listbox(values = fnames, change_submits=True, size=(60, 30), key='listbox')],
[sg.ReadButton('Next', size=(8,2)), sg.ReadButton('Prev', [sg.Button('Next', size=(8,2)), sg.Button('Prev',
size=(8,2)), file_num_display_elem]] size=(8,2)), file_num_display_elem]]
layout = [[sg.Column(col_files), sg.Column(col)]] layout = [[sg.Column(col_files), sg.Column(col)]]

View File

@ -0,0 +1,45 @@
import PySimpleGUI as sg
sg.ChangeLookAndFeel('GreenTan')
col1 = sg.Column([[sg.Text('in pane1', text_color='blue')],
[sg.T('Pane1')],
[sg.T('Pane1')],
])
col2 = sg.Column([[sg.Text('in pane2', text_color='red')],
[sg.T('Pane2')],
[sg.Input(key='_IN2_', do_not_clear=True)],
[sg.T('Pane2')],
[sg.T('Pane2')],
], key='_COL2_', visible=False)
col3 = sg.Column([[sg.Text('in pane 4', text_color='green')],
[sg.In(key='_IN3_', enable_events=True, do_not_clear=True)],
], key='_COL3_', visible=False)
col4 = sg.Column([[sg.Text('Column 4', text_color='firebrick')],
[sg.In()],
], key='_COL4_')
col5 = sg.Column([[sg.Frame('Frame', [[sg.Text('Column 5', text_color='purple')],
[sg.In()],
])]])
layout = [ [sg.Text('Click'), sg.Text('', key='_OUTPUT_')],
[sg.Button('Remove'), sg.Button('Add')],
[sg.Pane([col5, sg.Column([[sg.Pane([col1, col2, col4], handle_size=15, orientation='v', background_color='red', show_handle=True, visible=True, key='_PANE_', border_width=0, relief=sg.RELIEF_GROOVE),]]),col3 ], orientation='h', background_color=None, size=(160,160), relief=sg.RELIEF_RAISED, border_width=0)]
]
window = sg.Window('Window Title', default_element_size=(15,1), resizable=True, border_depth=5).Layout(layout)
while True: # Event Loop
event, values = window.Read()
print(event, values)
if event is None or event == 'Exit':
break
if event == 'Remove':
window.Element('_COL2_').Update(visible=False)
window.Element('_COL3_').Update(visible=False)
elif event == 'Add':
window.Element('_COL2_').Update(visible=True)
window.Element('_COL3_').Update(visible=True)
window.Element('_IN2_').Update(values['_IN3_'])
window.Close()

View File

@ -1,23 +1,11 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
""" layout = [[sg.Text('Please enter your Name, Address, Phone')],
Simple Form showing how to use keys on your input fields [sg.Text('Name', size=(10,1)), sg.InputText(key='-NAME-')],
""" [sg.Text('Address', size=(10,1)), sg.InputText(key='-ADDRESS-')],
[sg.Text('Phone', size=(10,1)), sg.InputText(key='-PHONE-')],
[sg.Button('Submit'), sg.Button('Cancel')]]
layout = [ window = sg.Window('Simple Data Entry Window', layout)
[sg.Text('Please enter your Name, Address, Phone')], event, values = window.read()
[sg.Text('Name', size=(15, 1)), sg.InputText('1', key='name'), sg.FileBrowse()], print(event, values['-NAME-'], values['-ADDRESS-'], values['-PHONE-'])
[sg.Text('Address', size=(15, 1)), sg.InputText('2', key='address')],
[sg.Text('Phone', size=(15, 1)), sg.InputText('3', key='phone')],
[sg.CloseButton('Submit'), sg.CloseButton('Cancel')]
]
window = sg.Window('Simple Data Entry Window').Layout(layout)
event, values = window.Read()
sg.Popup(event, values, values['name'], values['address'], values['phone'])

View File

@ -21,8 +21,8 @@ def DownloadSubtitlesGUI():
[sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))], [sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))],
[sg.T('YouTube Link'),sg.In(default_text='',size=(60,1), key='link', do_not_clear=True) ], [sg.T('YouTube Link'),sg.In(default_text='',size=(60,1), key='link', do_not_clear=True) ],
[sg.Output(size=(90,20), font='Courier 12')], [sg.Output(size=(90,20), font='Courier 12')],
[sg.ReadButton('Get List')], [sg.Button('Get List')],
[sg.T('Language Code'), combobox, sg.ReadButton('Download')], [sg.T('Language Code'), combobox, sg.Button('Download')],
[sg.Button('Exit', button_color=('white', 'firebrick3'))] [sg.Button('Exit', button_color=('white', 'firebrick3'))]
] ]