From 91a3178c7bb436d2b671a5efee3149ee0ab8a6cd Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 20 Sep 2018 10:03:17 -0400 Subject: [PATCH] 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)