Merge pull request #4358 from PySimpleGUI/Dev-latest

Better Button error handling when Unicode chars are used or if a bad …
This commit is contained in:
PySimpleGUI 2021-06-03 11:05:20 -04:00 committed by GitHub
commit 46a8223cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 24 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "4.43.0.3 Unreleased\nChanged get_versions string to be more clear, removed canvas from return values, cwd is automatically set to the folder of the application being launched when execute_py_file is called with cwd=None, popup_get_file changed to set parent=None if running on Mac" version = __version__ = "4.43.0.4 Unreleased\nChanged get_versions string to be more clear, removed canvas from return values, cwd is automatically set to the folder of the application being launched when execute_py_file is called with cwd=None, popup_get_file changed to set parent=None if running on Mac, better Button error handling when bad Unicode chars are used or bad colors"
__version__ = version.split()[0] # For PEP 396 and PEP 345 __version__ = version.split()[0] # For PEP 396 and PEP 345
@ -12620,29 +12620,31 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
bd = element.BorderWidth bd = element.BorderWidth
if btype != BUTTON_TYPE_REALTIME: try:
tkbutton = element.Widget = tk.Button(tk_row_frame, text=btext, width=width, height=height, if btype != BUTTON_TYPE_REALTIME:
command=element.ButtonCallBack, justify=tk.CENTER, bd=bd, font=font) tkbutton = element.Widget = tk.Button(tk_row_frame, text=btext, width=width, height=height,
else: command=element.ButtonCallBack, justify=tk.CENTER, bd=bd, font=font)
tkbutton = element.Widget = tk.Button(tk_row_frame, text=btext, width=width, height=height, else:
justify=tk.CENTER, bd=bd, font=font) tkbutton = element.Widget = tk.Button(tk_row_frame, text=btext, width=width, height=height,
tkbutton.bind('<ButtonRelease-1>', element.ButtonReleaseCallBack) justify=tk.CENTER, bd=bd, font=font)
tkbutton.bind('<ButtonPress-1>', element.ButtonPressCallBack) tkbutton.bind('<ButtonRelease-1>', element.ButtonReleaseCallBack)
if bc != (None, None) and COLOR_SYSTEM_DEFAULT not in bc: tkbutton.bind('<ButtonPress-1>', element.ButtonPressCallBack)
try: if bc != (None, None) and COLOR_SYSTEM_DEFAULT not in bc:
tkbutton.config(foreground=bc[0], background=bc[1], activebackground=bc[1]) tkbutton.config(foreground=bc[0], background=bc[1], activebackground=bc[1])
except Exception as e: else:
_error_popup_with_traceback('Button has bad color string', if bc[0] != COLOR_SYSTEM_DEFAULT:
'Error {}'.format(e), tkbutton.config(foreground=bc[0])
'Button Text: {}'.format(btext), if bc[1] != COLOR_SYSTEM_DEFAULT:
'Button key: {}'.format(element.Key), tkbutton.config(background=bc[1])
'Color string: {}'.format(bc), except Exception as e:
"Parent Window's Title: {}".format(toplevel_form.Title)) _error_popup_with_traceback('Button has a problem....',
else: 'The traceback information will not show the line in your layout with the problem, but it does tell you which window.',
if bc[0] != COLOR_SYSTEM_DEFAULT: 'Error {}'.format(e),
tkbutton.config(foreground=bc[0]) # 'Button Text: {}'.format(btext),
if bc[1] != COLOR_SYSTEM_DEFAULT: # 'Button key: {}'.format(element.Key),
tkbutton.config(background=bc[1]) # 'Color string: {}'.format(bc),
"Parent Window's Title: {}".format(toplevel_form.Title))
if bd == 0 and not running_mac(): if bd == 0 and not running_mac():
tkbutton.config(relief=tk.FLAT) tkbutton.config(relief=tk.FLAT)