From 91a3178c7bb436d2b671a5efee3149ee0ab8a6cd Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 20 Sep 2018 10:03:17 -0400 Subject: [PATCH 1/2] Changed MsgBox to Popup, fix for when button target is key --- Demo_Compare_Files.py | 14 ++++++++------ PySimpleGUI.py | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Demo_Compare_Files.py b/Demo_Compare_Files.py index 73cdf604..b00fc5fb 100644 --- a/Demo_Compare_Files.py +++ b/Demo_Compare_Files.py @@ -5,16 +5,18 @@ sg.SetOptions(button_color=sg.COLOR_SYSTEM_DEFAULT) def GetFilesToCompare(): with sg.FlexForm('File Compare') as form: form_rows = [[sg.Text('Enter 2 files to comare')], - [sg.Text('File 1', size=(15, 1)), sg.InputText(), sg.FileBrowse()], - [sg.Text('File 2', size=(15, 1)), sg.InputText(), sg.FileBrowse()], + [sg.Text('File 1', size=(15, 1)), sg.InputText(key='file1'), sg.FileBrowse()], + [sg.Text('File 2', size=(15, 1)), sg.InputText(key='file2'), sg.FileBrowse(target='file2')], [sg.Submit(), sg.Cancel()]] button, values = form.LayoutAndRead(form_rows) return button, values def main(): - button, (f1, f2) = GetFilesToCompare() + button, values = GetFilesToCompare() + f1 = values['file1'] + f2 = values['file2'] if any((button != 'Submit', f1 =='', f2 == '')): - sg.MsgBoxError('Operation cancelled') + sg.PopupError('Operation cancelled') exit(69) with open(f1, 'rb') as file1: @@ -24,11 +26,11 @@ def main(): for i, x in enumerate(a): if x != b[i]: - sg.MsgBox('Compare results for files', f1, f2, '**** Mismatch at offset {} ****'.format(i)) + sg.Popup('Compare results for files', f1, f2, '**** Mismatch at offset {} ****'.format(i)) break else: if len(a) == len(b): - sg.MsgBox('**** The files are IDENTICAL ****') + sg.Popup('**** The files are IDENTICAL ****') if __name__ == '__main__': diff --git a/PySimpleGUI.py b/PySimpleGUI.py index d116fc44..5d9d7cd6 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -969,7 +969,7 @@ class Button(Element): if target == (None, None): strvar = self.TKStringVar else: - if len(target) == 2: + if not isinstance(target, str): if target[0] < 0: target = [self.Position[0] + target[0], target[1]] target_element = self.ParentForm._GetElementAtLocation(target) @@ -2179,6 +2179,8 @@ def ReadFormButton(button_text, image_filename=None, image_size=(None, None),ima return Button(BUTTON_TYPE_READ_FORM, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) ReadButton = ReadFormButton +RButton = ReadFormButton +RFButton = ReadFormButton # ------------------------- Realtime BUTTON Element lazy function ------------------------- # @@ -2552,7 +2554,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): tktext_label.configure(background=element.BackgroundColor) if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None: tktext_label.configure(fg=element.TextColor) - tktext_label.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1], fill='both', expand=True) + tktext_label.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1], expand=True) element.TKText = tktext_label if element.ClickSubmits: tktext_label.bind('', element.TextClickedHandler) From 53db1545d8a54a219fbbbf8a5d1d7a48992dbff4 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 20 Sep 2018 10:41:47 -0400 Subject: [PATCH 2/2] Shuffled around parms in calls to Button so that Button can be called by user. Changed all MsgBox calls to Popup --- Demo_Color.py | 1 - Demo_Desktop_Widget_CPU_Graph.py | 73 ++++++++++++++++++++++++++ Demo_Desktop_Widget_CPU_Utilization.py | 2 + Demo_Desktop_Widget_Timer.py | 12 ++++- Demo_Dictionary.py | 2 +- Demo_ElementBrowser.py | 24 --------- Demo_Func_Callback_Simulation.py | 2 +- Demo_Graph_Element.py | 66 +++++++++++++++++++++++ Demo_HowDoI.py | 5 +- Demo_Keyboard.py | 9 ++-- Demo_MIDI_Player.py | 8 +-- Demo_Menus.py | 2 +- Demo_NonBlocking_Form.py | 2 +- Demo_Pi_LEDs.py | 2 +- Demo_Popups.py | 11 ++-- Demo_Recipes.py | 12 ++--- Demo_Tabbed_Form.py | 4 +- Demo_Table_Element.py | 3 +- PySimpleGUI.py | 58 ++++++++++---------- 19 files changed, 212 insertions(+), 86 deletions(-) create mode 100644 Demo_Desktop_Widget_CPU_Graph.py delete mode 100644 Demo_ElementBrowser.py create mode 100644 Demo_Graph_Element.py diff --git a/Demo_Color.py b/Demo_Color.py index ba481a39..e826ce88 100644 --- a/Demo_Color.py +++ b/Demo_Color.py @@ -1707,7 +1707,6 @@ def main(): complementary_hex = get_complementary_hex(color_hex) complementary_color = get_name_from_hex(complementary_hex) - # g.MsgBox('Colors', 'The RBG value is', rgb, 'color and comp are', color_string, compl) layout = [[sg.Text('That color and it\'s compliment are shown on these buttons. This form auto-closes')], [sg.Button(button_text=color_name, button_color=(color_hex, complementary_hex))], [sg.Button(button_text=complementary_hex + ' ' + complementary_color, button_color=(complementary_hex , color_hex), size=(30, 1))], diff --git a/Demo_Desktop_Widget_CPU_Graph.py b/Demo_Desktop_Widget_CPU_Graph.py new file mode 100644 index 00000000..ddc6663a --- /dev/null +++ b/Demo_Desktop_Widget_CPU_Graph.py @@ -0,0 +1,73 @@ +import time +import random +import psutil +from threading import Thread +import PySimpleGUI as sg + + +STEP_SIZE=3 +SAMPLES = 300 +SAMPLE_MAX = 500 +CANVAS_SIZE = (300,200) + + +g_interval = .25 +g_cpu_percent = 0 +g_procs = None +g_exit = False + +def CPU_thread(args): + global g_interval, g_cpu_percent, g_procs, g_exit + + while not g_exit: + try: + g_cpu_percent = psutil.cpu_percent(interval=g_interval) + g_procs = psutil.process_iter() + except: + pass + +def main(): + global g_exit, g_response_time + # start ping measurement thread + + sg.ChangeLookAndFeel('Black') + sg.SetOptions(element_padding=(0,0)) + + layout = [ [sg.Quit( button_color=('white','black')), sg.T('', pad=((100,0),0), font='Any 15', key='output')], + [sg.Graph(CANVAS_SIZE, (0,0), (SAMPLES,SAMPLE_MAX),background_color='black', key='graph')],] + + form = sg.FlexForm('CPU Graph', grab_anywhere=True, keep_on_top=True, background_color='black', no_titlebar=True, use_default_focus=False) + form.Layout(layout) + + graph = form.FindElement('graph') + output = form.FindElement('output') + # start cpu measurement thread + thread = Thread(target=CPU_thread,args=(None,)) + thread.start() + + last_cpu = i = 0 + prev_x, prev_y = 0, 0 + while True: # the Event Loop + time.sleep(.5) + button, values = form.ReadNonBlocking() + if button == 'Quit' or values is None: # always give ths user a way out + break + # do CPU measurement and graph it + current_cpu = int(g_cpu_percent*10) + if current_cpu == last_cpu: + continue + output.Update(current_cpu/10) # show current cpu usage at top + if current_cpu > SAMPLE_MAX: + current_cpu = SAMPLE_MAX + new_x, new_y = i, current_cpu + if i >= SAMPLES: + graph.Move(-STEP_SIZE,0) # shift graph over if full of data + prev_x = prev_x - STEP_SIZE + graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white') + prev_x, prev_y = new_x, new_y + i += STEP_SIZE if i < SAMPLES else 0 + last_cpu = current_cpu + +if __name__ == '__main__': + main() + exit(69) diff --git a/Demo_Desktop_Widget_CPU_Utilization.py b/Demo_Desktop_Widget_CPU_Utilization.py index 69178101..da675f6c 100644 --- a/Demo_Desktop_Widget_CPU_Utilization.py +++ b/Demo_Desktop_Widget_CPU_Utilization.py @@ -37,6 +37,8 @@ def CPU_thread(args): def main(): global g_interval, g_procs, g_exit + yesno = sg.PopupYesNo('My popup') + # ---------------- Create Form ---------------- sg.ChangeLookAndFeel('Black') form_rows = [[sg.Text('', size=(8,1), font=('Helvetica', 20),text_color=sg.YELLOWS[0], justification='center', key='text')], diff --git a/Demo_Desktop_Widget_Timer.py b/Demo_Desktop_Widget_Timer.py index 367e83f0..b8ce0ae9 100644 --- a/Demo_Desktop_Widget_Timer.py +++ b/Demo_Desktop_Widget_Timer.py @@ -1,6 +1,12 @@ import PySimpleGUI as sg import time +""" + Timer Desktop Widget Creates a floating timer that is always on top of other windows You move it by grabbing anywhere on the window Good example of how to do a non-blocking, polling program using PySimpleGUI Can be used to poll hardware when running on a Pi NOTE - you will get a warning message printed when you exit using exit button. + It will look something like: invalid command name \"1616802625480StopMove\" +""" + + # ---------------- Create Form ---------------- sg.ChangeLookAndFeel('Black') sg.SetOptions(element_padding=(0, 0)) @@ -8,8 +14,8 @@ sg.SetOptions(element_padding=(0, 0)) form_rows = [[sg.Text('')], [sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')], [sg.ReadFormButton('Pause', key='button', button_color=('white', '#001480')), - sg.ReadFormButton('Reset', button_color=('white', '#007339')), - sg.Exit(button_color=('white', 'firebrick4'))]] + sg.ReadFormButton('Reset', button_color=('white', '#007339'), key='Reset'), + sg.Exit(button_color=('white', 'firebrick4'), key='Exit')]] form = sg.FlexForm('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True) form.Layout(form_rows) @@ -25,6 +31,8 @@ while (True): current_time = int(round(time.time() * 100)) - start_time else: button, values = form.Read() + if button == 'button': + button = form.FindElement(button).GetText() # --------- Do Button Operations -------- if values is None or button == 'Exit': break diff --git a/Demo_Dictionary.py b/Demo_Dictionary.py index 1b918b7b..06d8c6e7 100644 --- a/Demo_Dictionary.py +++ b/Demo_Dictionary.py @@ -14,5 +14,5 @@ layout = [ button, values = form.LayoutAndRead(layout) -sg.MsgBox(button, values, values['name'], values['address'], values['phone']) +sg.Popup(button, values, values['name'], values['address'], values['phone']) diff --git a/Demo_ElementBrowser.py b/Demo_ElementBrowser.py deleted file mode 100644 index b75d59fe..00000000 --- a/Demo_ElementBrowser.py +++ /dev/null @@ -1,24 +0,0 @@ -import PySimpleGUI as sg - -def ShowMainForm(): - - listbox_values = ('Text', 'InputText', 'Checkbox', 'Radio Button', 'Listbox', 'Slider' ) - - column2 = [ [sg.Output(size=(50, 20))], - [sg.ReadFormButton('Show Element'), sg.SimpleButton('Exit')]] - - column1 = [[sg.Listbox(values=listbox_values, size=(20, len(listbox_values)), key='listbox')], - [sg.Text('', size=(10, 15))]] - - layout = [[sg.Column(column1) , sg.Column(column2)]] - - form = sg.FlexForm('Element Browser') - form.Layout(layout) - while True: - button, values = form.Read() - if button is None or button == 'Exit': - break - sg.MsgBox(button, values['listbox'][0]) - - -ShowMainForm() diff --git a/Demo_Func_Callback_Simulation.py b/Demo_Func_Callback_Simulation.py index 618ff94e..198337c3 100644 --- a/Demo_Func_Callback_Simulation.py +++ b/Demo_Func_Callback_Simulation.py @@ -33,4 +33,4 @@ while True: break # All done! -sg.MsgBoxOK('Done') +sg.PopupOK('Done') diff --git a/Demo_Graph_Element.py b/Demo_Graph_Element.py new file mode 100644 index 00000000..174ce1fb --- /dev/null +++ b/Demo_Graph_Element.py @@ -0,0 +1,66 @@ +import ping +from threading import Thread +import time +import PySimpleGUI as sg + + +STEP_SIZE=1 +SAMPLES = 6000 +CANVAS_SIZE = (6000,500) + +# globale used to communicate with thread.. yea yea... it's working fine +g_exit = False +g_response_time = None +def ping_thread(args): + global g_exit, g_response_time + while not g_exit: + g_response_time = ping.quiet_ping('google.com', timeout=1000) + +def main(): + global g_exit, g_response_time + + # start ping measurement thread + thread = Thread(target=ping_thread, args=(None,)) + thread.start() + + sg.ChangeLookAndFeel('Black') + sg.SetOptions(element_padding=(0,0)) + + layout = [ [sg.T('Ping times to Google.com', font='Any 12'), sg.Quit(pad=((100,0), 0), button_color=('white', 'black'))], + [sg.Graph(CANVAS_SIZE, (0,0), (SAMPLES,500),background_color='black', key='graph')],] + + form = sg.FlexForm('Canvas test', grab_anywhere=True, background_color='black', no_titlebar=False, use_default_focus=False) + form.Layout(layout) + + form.Finalize() + graph = form.FindElement('graph') + + prev_response_time = None + i=0 + prev_x, prev_y = 0, 0 + while True: + time.sleep(.2) + + button, values = form.ReadNonBlocking() + if button == 'Quit' or values is None: + break + if g_response_time is None or prev_response_time == g_response_time: + continue + new_x, new_y = i, g_response_time[0] + prev_response_time = g_response_time + if i >= SAMPLES: + graph.Move(-STEP_SIZE,0) + prev_x = prev_x - STEP_SIZE + graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white') + # form.FindElement('graph').DrawPoint((new_x, new_y), color='red') + prev_x, prev_y = new_x, new_y + i += STEP_SIZE if i < SAMPLES else 0 + + # tell thread we're done. wait for thread to exit + g_exit = True + thread.join() + + +if __name__ == '__main__': + main() + exit(69) \ No newline at end of file diff --git a/Demo_HowDoI.py b/Demo_HowDoI.py index ae1b251c..83c7c660 100644 --- a/Demo_HowDoI.py +++ b/Demo_HowDoI.py @@ -33,8 +33,9 @@ def HowDoI(): layout = [ [sg.Text('Ask and your answer will appear here....', size=(40, 1))], [sg.Output(size=(127, 30), font=('Helvetica 10'))], - [ sg.Spin(values=(1, 2, 3, 4), initial_value=1, size=(2, 1), key='Num Answers', font='Helvetica 15'), sg.T('Num Answers',font='Helvetica 15'), sg.Checkbox('Display Full Text', key='full text', font='Helvetica 15'), - sg.T('Command History'), sg.T('', size=(40,3), text_color=sg.BLUES[0], key='history')], + [ 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.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.ReadFormButton('SEND', button_color=(sg.YELLOWS[0], sg.BLUES[0]), bind_return_key=True), sg.SimpleButton('EXIT', button_color=(sg.YELLOWS[0], sg.GREENS[0]))] diff --git a/Demo_Keyboard.py b/Demo_Keyboard.py index bde67fdb..9bbde27d 100644 --- a/Demo_Keyboard.py +++ b/Demo_Keyboard.py @@ -4,17 +4,16 @@ import PySimpleGUI as sg # If want to use the space bar, then be sure and disable the "default focus" with sg.FlexForm("Keyboard Test", return_keyboard_events=True, use_default_focus=False) as form: - text_elem = sg.Text("", size=(18,1)) layout = [[sg.Text("Press a key or scroll mouse")], - [text_elem], - [sg.SimpleButton("OK")]] + [sg.Text("", size=(18,1), key='text')], + [sg.SimpleButton("OK", key='OK')]] form.Layout(layout) # ---===--- Loop taking in user input --- # while True: button, value = form.Read() - - if button == "OK" or (button is None and value is None): + text_elem = form.FindElement('text') + if button in ("OK", None): print(button, "exiting") break if len(button) == 1: diff --git a/Demo_MIDI_Player.py b/Demo_MIDI_Player.py index dbaabc0c..3e4e5008 100644 --- a/Demo_MIDI_Player.py +++ b/Demo_MIDI_Player.py @@ -120,12 +120,12 @@ def main(): button, values = pback.PlayerChooseSongGUI() if button != 'PLAY': - g.MsgBoxCancel('Cancelled...\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2) + g.PopupCancel('Cancelled...\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2) exit(69) if values['device']: midi_port = values['device'][0] else: - g.MsgBoxCancel('No devices found\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2) + g.PopupCancel('No devices found\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2) batch_folder = values['folder'] midi_filename = values['midifile'] @@ -138,7 +138,7 @@ def main(): filelist = [midi_filename,] filetitles = [os.path.basename(midi_filename),] else: - g.MsgBoxError('*** Error - No MIDI files specified ***') + g.PopupError('*** Error - No MIDI files specified ***') exit(666) # ------ LOOP THROUGH MULTIPLE FILES --------------------------------------------------------- # @@ -162,7 +162,7 @@ def main(): mid = mido.MidiFile(filename=midi_filename) except: print('****** Exception trying to play MidiFile filename = {}***************'.format(midi_filename)) - g.MsgBoxError('Exception trying to play MIDI file:', midi_filename, 'Skipping file') + g.PopupError('Exception trying to play MIDI file:', midi_filename, 'Skipping file') continue # Build list of data contained in MIDI File using only track 0 diff --git a/Demo_Menus.py b/Demo_Menus.py index 7c0df18d..8462881f 100644 --- a/Demo_Menus.py +++ b/Demo_Menus.py @@ -28,7 +28,7 @@ def TestMenus(): # ------ GUI Defintion ------ # layout = [ - [sg.Menu(menu_def)], + [sg.Menu(menu_def, tearoff=True)], [sg.Output(size=(60,20))], [sg.In('Test', key='input', do_not_clear=True)] ] diff --git a/Demo_NonBlocking_Form.py b/Demo_NonBlocking_Form.py index 09071a6b..b08b85c2 100644 --- a/Demo_NonBlocking_Form.py +++ b/Demo_NonBlocking_Form.py @@ -100,7 +100,7 @@ def main(): RemoteControlExample() StatusOutputExample() StatusOutputExample() - sg.MsgBox('End of non-blocking demonstration') + sg.Popup('End of non-blocking demonstration') # StatusOutputExample_context_manager() diff --git a/Demo_Pi_LEDs.py b/Demo_Pi_LEDs.py index ec89ab11..6ec26c5e 100644 --- a/Demo_Pi_LEDs.py +++ b/Demo_Pi_LEDs.py @@ -51,4 +51,4 @@ while True: FlashLED() form.FindElement('output').Update('') -rg.MsgBox('Done... exiting') +rg.Popup('Done... exiting') diff --git a/Demo_Popups.py b/Demo_Popups.py index f90a4105..e5315ad1 100644 --- a/Demo_Popups.py +++ b/Demo_Popups.py @@ -1,10 +1,13 @@ import PySimpleGUI as sg +# Here, have some windows on me.... +[sg.PopupNoWait(location=(10*x,0)) for x in range(10)] + print (sg.PopupYesNo('Yes No')) -print(sg.PopupGetText('Get text', background_color='blue', text_color='white', location=(1000,200))) -print(sg.PopupGetFile('Get file', background_color='blue', text_color='white')) -print(sg.PopupGetFolder('Get folder', background_color='blue', text_color='white')) +print(sg.PopupGetText('Get text', location=(1000,200))) +print(sg.PopupGetFile('Get file')) +print(sg.PopupGetFolder('Get folder')) sg.Popup('Simple popup') @@ -13,7 +16,7 @@ sg.PopupNonBlocking('Non Blocking', location=(500,500)) sg.PopupNoTitlebar('No titlebar') sg.PopupNoBorder('No border') sg.PopupNoFrame('No frame') -sg.PopupNoButtons('No Buttons') +# sg.PopupNoButtons('No Buttons') # don't mix with non-blocking... disaster ahead... sg.PopupCancel('Cancel') sg.PopupOKCancel('OK Cancel') sg.PopupAutoClose('Autoclose') diff --git a/Demo_Recipes.py b/Demo_Recipes.py index 972a199a..585fd133 100644 --- a/Demo_Recipes.py +++ b/Demo_Recipes.py @@ -12,9 +12,9 @@ def SourceDestFolders(): button, values = form.LayoutAndRead(form_rows) if button is 'Submit': - sg.MsgBox('Submitted', values, 'The user entered source:', values['source'], 'Destination folder:', values['dest'], 'Using button', button) + sg.Popup('Submitted', values, 'The user entered source:', values['source'], 'Destination folder:', values['dest'], 'Using button', button) else: - sg.MsgBoxError('Cancelled', 'User Cancelled') + sg.PopupError('Cancelled', 'User Cancelled') def MachineLearningGUI(): @@ -75,7 +75,7 @@ def Everything(): button, values = form.LayoutAndRead(layout) - sg.MsgBox('Title', 'The results of the form.', 'The button clicked was "{}"'.format(button), 'The values are', values) + sg.Popup('Title', 'The results of the form.', 'The button clicked was "{}"'.format(button), 'The values are', values) # Should you decide not to use a context manager, then try this form as your starting point # Be aware that tkinter, which this is based on, is picky about who frees up resources, especially if @@ -107,7 +107,7 @@ def Everything_NoContextManager(): button, values = form.LayoutAndRead(layout) del(form) - sg.MsgBox('Title', 'The results of the form.', 'The button clicked was "{}"'.format(button), 'The values are', values) + sg.Popup('Title', 'The results of the form.', 'The button clicked was "{}"'.format(button), 'The values are', values) def ProgressMeter(): @@ -209,7 +209,7 @@ def OneLineGUI(): def main(): # button, (filename,) = OneLineGUI() # DebugTe`st() - sg.MsgBox('Hello') + sg.Popup('Hello') ChatBot() Everything() SourceDestFolders() @@ -230,7 +230,7 @@ def main(): Everything_NoContextManager() NonBlockingPeriodicUpdateForm_ContextManager() - sg.MsgBox('Done with all recipes') + sg.Popup('Done with all recipes') if __name__ == '__main__': main() diff --git a/Demo_Tabbed_Form.py b/Demo_Tabbed_Form.py index 3cde91ca..d63d1205 100644 --- a/Demo_Tabbed_Form.py +++ b/Demo_Tabbed_Form.py @@ -73,7 +73,7 @@ def eBaySuperSearcherGUI(): layout_tab_2.append([sg.Text('Typical US Search String')]) layout_tab_2.append([sg.InputText(size=(100,1), default_text='gruen -sara -quarz -quartz -embassy -bob -robert -elephants -adidas -LED ')]) layout_tab_2.append([sg.Text('_' * 100, size=(75, 1))]) - layout_tab_2.append([sg.Submit(button_color=('red', 'yellow')), sg.Cancel(button_color=('white', 'blue'))]) + layout_tab_2.append([sg.ReadButton('Submit', button_color=('red', 'yellow')), sg.Cancel(button_color=('white', 'blue'))]) results = sg.ShowTabbedForm('eBay Super Searcher', (form,layout_tab_1,'Where To Save'), (form2, layout_tab_2, 'Categories & Search String')) @@ -84,4 +84,4 @@ if __name__ == '__main__': # sg.SetOptions(background_color='white') results = eBaySuperSearcherGUI() print(results) - sg.MsgBox('Results', results) \ No newline at end of file + sg.Popup('Results', results) \ No newline at end of file diff --git a/Demo_Table_Element.py b/Demo_Table_Element.py index 7a72088d..85ddef33 100644 --- a/Demo_Table_Element.py +++ b/Demo_Table_Element.py @@ -1,8 +1,7 @@ import csv import PySimpleGUI as sg -# filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),)) -filename = 'C:/Python/PycharmProjects/GooeyGUI/CSV/Gruen Movement Catalog V5.3 for Lucid less data 2017-08-30.csv' +filename = sg.PopupGetFile('filename to open', no_window=True, file_types=(("CSV Files","*.csv"),)) # --- populate table with file contents --- # data = [] if filename is not None: diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 5d9d7cd6..70d72be7 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -901,7 +901,7 @@ class Output(Element): # Button Class # # ---------------------------------------------------------------------- # class Button(Element): - def __init__(self, button_type=BUTTON_TYPE_CLOSES_WIN, target=(None, None), button_text='', file_types=(("ALL Files", "*.*"),), initial_folder=None, image_filename=None, image_size=(None, None), image_subsample=None, border_width=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, default_value = None, font=None, bind_return_key=False, focus=False, pad=None, key=None): + def __init__(self, button_text='', button_type=BUTTON_TYPE_CLOSES_WIN, target=(None, None), file_types=(("ALL Files", "*.*"),), initial_folder=None, image_filename=None, image_size=(None, None), image_subsample=None, border_width=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, default_value = None, font=None, bind_return_key=False, focus=False, pad=None, key=None): ''' Button Element - Specifies all types of buttons :param button_type: @@ -933,7 +933,7 @@ class Button(Element): self.BindReturnKey = bind_return_key self.Focus = focus self.TKCal = None - self.DefaultValue = None + self.DefaultValue = default_value self.InitialFolder = initial_folder super().__init__(ELEM_TYPE_BUTTON, scale=scale, size=size, font=font, pad=pad, key=key) @@ -2108,75 +2108,75 @@ class UberForm(): # ------------------------- FOLDER BROWSE Element lazy function ------------------------- # -def FolderBrowse(target=(ThisRow, -1), button_text='Browse', initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): - return Button(BUTTON_TYPE_BROWSE_FOLDER, target=target, button_text=button_text, initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) +def FolderBrowse(button_text='Browse', target=(ThisRow, -1), initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): + return Button(button_text=button_text, button_type=BUTTON_TYPE_BROWSE_FOLDER, target=target, initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) # ------------------------- FILE BROWSE Element lazy function ------------------------- # -def FileBrowse(target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), button_text='Browse', initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): - return Button(BUTTON_TYPE_BROWSE_FILE, target, button_text=button_text, file_types=file_types,initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) +def FileBrowse( button_text='Browse',target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): + return Button(button_text=button_text, button_type=BUTTON_TYPE_BROWSE_FILE, target=target, file_types=file_types,initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) # ------------------------- FILES BROWSE Element (Multiple file selection) lazy function ------------------------- # -def FilesBrowse(target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), button_text='Browse', initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): - return Button(BUTTON_TYPE_BROWSE_FILES, target, button_text=button_text, file_types=file_types, initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) +def FilesBrowse(button_text='Browse',target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): + return Button(button_text=button_text, button_type=BUTTON_TYPE_BROWSE_FILES, target=target, file_types=file_types, initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) # ------------------------- FILE BROWSE Element lazy function ------------------------- # -def FileSaveAs(target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), button_text='Save As...', initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): - return Button(BUTTON_TYPE_SAVEAS_FILE, target, button_text=button_text, file_types=file_types, initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) +def FileSaveAs(button_text='Save As...',target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): + return Button(button_text=button_text, button_type=BUTTON_TYPE_SAVEAS_FILE, target=target, file_types=file_types, initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) # ------------------------- SAVE AS Element lazy function ------------------------- # -def SaveAs(target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), button_text='Save As...', initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): - return Button(BUTTON_TYPE_SAVEAS_FILE, target, button_text=button_text, file_types=file_types, initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) +def SaveAs(button_text='Save As...',target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),),initial_folder=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, pad=None, key=None): + return Button(button_text=button_text, button_type=BUTTON_TYPE_SAVEAS_FILE, target=target, file_types=file_types, initial_folder=initial_folder, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, pad=pad, key=key) # ------------------------- SAVE BUTTON Element lazy function ------------------------- # def Save(button_text='Save', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True,font=None, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text,button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- SUBMIT BUTTON Element lazy function ------------------------- # def Submit(button_text='Submit', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True,font=None, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button( button_text=button_text,button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- OPEN BUTTON Element lazy function ------------------------- # def Open(button_text='Open', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True,font=None, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text,button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- OK BUTTON Element lazy function ------------------------- # def OK(button_text='OK', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True, font=None,focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text,button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- YES BUTTON Element lazy function ------------------------- # def Ok(button_text='Ok', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True, font=None,focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text,button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- CANCEL BUTTON Element lazy function ------------------------- # def Cancel(button_text='Cancel', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text, button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- QUIT BUTTON Element lazy function ------------------------- # def Quit(button_text='Quit', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text,button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- Exit BUTTON Element lazy function ------------------------- # def Exit(button_text='Exit', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text, button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- YES BUTTON Element lazy function ------------------------- # def Yes(button_text='Yes', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None,font=None, bind_return_key=True, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text, button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- NO BUTTON Element lazy function ------------------------- # def No(button_text='No', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None,font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text, button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- NO BUTTON Element lazy function ------------------------- # def Help(button_text='Help', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None,font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text,button_type=BUTTON_TYPE_CLOSES_WIN, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- GENERIC BUTTON Element lazy function ------------------------- # def SimpleButton(button_text, image_filename=None, image_size=(None, None), image_subsample=None, border_width=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, button_text=button_text, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text,button_type=BUTTON_TYPE_CLOSES_WIN, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- GENERIC BUTTON Element lazy function ------------------------- # def ReadFormButton(button_text, image_filename=None, image_size=(None, None),image_subsample=None,border_width=None,scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_READ_FORM, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button( button_text=button_text, button_type=BUTTON_TYPE_READ_FORM, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width,scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) ReadButton = ReadFormButton RButton = ReadFormButton @@ -2185,17 +2185,17 @@ RFButton = ReadFormButton # ------------------------- Realtime BUTTON Element lazy function ------------------------- # def RealtimeButton(button_text, image_filename=None, image_size=(None, None),image_subsample=None,border_width=None,scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_REALTIME, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button( button_text=button_text,button_type=BUTTON_TYPE_REALTIME, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- Dummy BUTTON Element lazy function ------------------------- # def DummyButton(button_text, image_filename=None, image_size=(None, None),image_subsample=None,border_width=None,scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CLOSES_WIN_ONLY, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text, button_type= BUTTON_TYPE_CLOSES_WIN_ONLY, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width,scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- Calendar Chooser Button lazy function ------------------------- # def CalendarButton(button_text, target=(None,None), image_filename=None, image_size=(None, None), image_subsample=None, border_width=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_CALENDAR_CHOOSER, target=target, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, button_text=button_text, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text, button_type=BUTTON_TYPE_CALENDAR_CHOOSER, target=target, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) # ------------------------- Calendar Chooser Button lazy function ------------------------- # def ColorChooserButton(button_text, target=(None,None), image_filename=None, image_size=(None, None), image_subsample=None, border_width=None, scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False, pad=None, key=None): - return Button(BUTTON_TYPE_COLOR_CHOOSER, target=target, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, button_text=button_text, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) + return Button(button_text=button_text,button_type=BUTTON_TYPE_COLOR_CHOOSER, target=target, image_filename=image_filename, image_size=image_size, image_subsample=image_subsample, border_width=border_width, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus, pad=pad, key=key) ##################################### ----- RESULTS ------ ################################################## def AddToReturnDictionary(form, element, value):