PySimpleGUI 6.3__py3-none-any.whl → 6.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,16 +54,16 @@
54
54
 
55
55
  """
56
56
 
57
- version = "6.3"
57
+ version = "6.4"
58
58
 
59
59
 
60
60
 
61
61
  """
62
62
  Changelog since last major release
63
63
 
64
- 6.3 2-Aug-2026 Released to GitHub
64
+ 6.4 02-Nov-2026 Version 6.4 release.
65
65
  """
66
-
66
+
67
67
 
68
68
  __version__ = version.split()[0] # For PEP 396 and PEP 345
69
69
 
@@ -335,6 +335,18 @@ def running_replit():
335
335
  return False
336
336
 
337
337
 
338
+ def fname():
339
+ """
340
+ Returns a the name of the function that the code is running inside of. Used when debugging.
341
+ Usage:
342
+ print(f'[{fname()}] starting...') # → [my_func] starting...
343
+
344
+ :return: The name of the function being executed
345
+ :rtype: (str)
346
+ """
347
+ return sys._getframe(1).f_code.co_name # 1 = caller's frame
348
+
349
+
338
350
  # Handy python statements to increment and decrement with wrapping that I don't want to forget
339
351
  # count = (count + (MAX - 1)) % MAX # Decrement - roll over to MAX from 0
340
352
  # count = (count + 1) % MAX # Increment to MAX then roll over to 0
@@ -383,6 +395,7 @@ TOOLTIP_TEXT_COLOR = '#000000' # Black
383
395
  TOOLTIP_FONT = None
384
396
  DEFAULT_USE_BUTTON_SHORTCUTS = False
385
397
  DEFAULT_DICT_TO_STRING_WIDTH = 80
398
+ DEFAULT_SET_TOOLTIP_TO_ELEMENT_KEY = False # If true, then the tooltip will be set = to the element's key for all elements
386
399
  #################### COLOR STUFF ####################
387
400
  BLUES = ("#082567", "#0A37A3", "#00345B")
388
401
  PURPLES = ("#480656", "#4F2398", "#380474")
@@ -901,7 +914,7 @@ class ToolTip:
901
914
  self.text_color = text_color or TOOLTIP_TEXT_COLOR
902
915
  self.background_color = background_color or TOOLTIP_BACKGROUND_COLOR
903
916
  self.offset = offset
904
- self.font = font
917
+ self.font = font or TOOLTIP_FONT
905
918
 
906
919
  def enter(self, event=None):
907
920
  """
@@ -1036,6 +1049,9 @@ class Element:
1036
1049
  :type sbar_relief: (str)
1037
1050
  """
1038
1051
 
1052
+ if key is None:
1053
+ key = f'KeyID {hex(id(self)).upper()[2:]}'
1054
+
1039
1055
  if size is not None and size != (None, None):
1040
1056
  if isinstance(size, int):
1041
1057
  size = (size, 1)
@@ -1072,6 +1088,8 @@ class Element:
1072
1088
  self.BackgroundColor = background_color if background_color is not None else DEFAULT_ELEMENT_BACKGROUND_COLOR
1073
1089
  self.TextColor = text_color if text_color is not None else DEFAULT_ELEMENT_TEXT_COLOR
1074
1090
  self.Key = key # dictionary key for return values
1091
+ if Window._set_tooltip_to_element_key and key:
1092
+ tooltip = f'{key}'
1075
1093
  self.Tooltip = tooltip
1076
1094
  self.TooltipObject = None # type: ToolTip | None
1077
1095
  self._visible = visible
@@ -1230,7 +1248,8 @@ class Element:
1230
1248
  pass
1231
1249
  return
1232
1250
  self.TKRightClickMenu.tk_popup(event.x_root, event.y_root, 0)
1233
- self.TKRightClickMenu.grab_release()
1251
+ if not running_linux():
1252
+ self.TKRightClickMenu.grab_release()
1234
1253
  if self.Type == ELEM_TYPE_GRAPH:
1235
1254
  self._update_position_for_returned_values(event)
1236
1255
  self.ParentForm._right_click_menu_element = self
@@ -1875,18 +1894,12 @@ class Element:
1875
1894
  pass
1876
1895
  top_menu = tk.Menu(self.ParentForm.TKroot, tearoff=self.ParentForm.right_click_menu_tearoff, tearoffcommand=self._tearoff_menu_callback)
1877
1896
  # Style the meny
1878
- if self.ParentForm.right_click_menu_background_color not in (COLOR_SYSTEM_DEFAULT, None):
1879
- top_menu.config(bg=self.ParentForm.right_click_menu_background_color)
1880
- if self.ParentForm.right_click_menu_text_color not in (COLOR_SYSTEM_DEFAULT, None):
1881
- top_menu.config(fg=self.ParentForm.right_click_menu_text_color)
1882
- if self.ParentForm.right_click_menu_disabled_text_color not in (COLOR_SYSTEM_DEFAULT, None):
1883
- top_menu.config(disabledforeground=self.ParentForm.right_click_menu_disabled_text_color)
1884
- if self.ParentForm.right_click_menu_font is not None:
1885
- top_menu.config(font=self.ParentForm.right_click_menu_font)
1886
- if self.ParentForm.right_click_menu_selected_colors[0] not in (COLOR_SYSTEM_DEFAULT, None):
1887
- top_menu.config(activeforeground=self.ParentForm.right_click_menu_selected_colors[0])
1888
- if self.ParentForm.right_click_menu_selected_colors[1] not in (COLOR_SYSTEM_DEFAULT, None):
1889
- top_menu.config(activebackground=self.ParentForm.right_click_menu_selected_colors[1])
1897
+ top_menu.config(bg=color_check(self.ParentForm.right_click_menu_background_color))
1898
+ top_menu.config(fg=color_check(self.ParentForm.right_click_menu_text_color))
1899
+ top_menu.config(disabledforeground=color_check_blank(self.ParentForm.right_click_menu_disabled_text_color))
1900
+ top_menu.config(activeforeground=color_check(self.ParentForm.right_click_menu_selected_colors[0]))
1901
+ top_menu.config(activebackground=color_check(self.ParentForm.right_click_menu_selected_colors[1]))
1902
+ top_menu.config(font=self.ParentForm.right_click_menu_font)
1890
1903
  AddMenuItem(top_menu, menu[1], self, right_click_menu=True)
1891
1904
  self.TKRightClickMenu = top_menu
1892
1905
  if propogate_to_window:
@@ -2231,25 +2244,24 @@ class Input(Element):
2231
2244
  return
2232
2245
 
2233
2246
  if background_color is not None:
2234
- if _widget_set_bg_color(self.TKEntry, background_color): # set background using refactored function to check for errors, etc.
2235
- self.BackgroundColor = background_color
2247
+ self.TKEntry.config(bg=color_check(background_color)) # set background using refactored function to check for errors, etc.
2248
+ self.BackgroundColor = background_color
2236
2249
  if text_color is not None:
2237
- # self.TKEntry.configure(fg=text_color)
2238
- if _widget_set_fg_color(self.TKEntry, text_color): # set foreground using refactored function to check for errors, etc.
2239
- self.TextColor = text_color # save new color if all is OK
2250
+ self.TKEntry.configure(fg=color_check(text_color))
2251
+ self.TextColor = text_color # save new color if all is OK
2240
2252
 
2241
2253
  if disabled is True:
2242
2254
  if self.UseReadonlyForDisable:
2243
- _widget_set_fg_color(self.TKEntry, self.disabled_readonly_text_color)
2244
- _widget_set_bg_color(self.TKEntry, self.disabled_readonly_background_color)
2255
+ self.TKEntry.config(fg=color_check(self.disabled_readonly_text_color))
2256
+ self.TKEntry.config(bg=color_check(self.disabled_readonly_background_color))
2245
2257
  self.TKEntry['state'] = 'readonly'
2246
2258
  else:
2247
2259
  self.TKEntry['state'] = 'disabled'
2248
2260
  self.Disabled = True
2249
2261
  elif disabled is False:
2250
2262
  self.TKEntry['state'] = 'normal'
2251
- _widget_set_fg_color(self.TKEntry, self.TextColor)
2252
- _widget_set_bg_color(self.TKEntry, self.BackgroundColor)
2263
+ self.TKEntry.config(fg=color_check(self.TextColor))
2264
+ self.TKEntry.config(bg=color_check(self.BackgroundColor))
2253
2265
  # self.TKEntry.configure(fg=self.TextColor)
2254
2266
  self.Disabled = False
2255
2267
 
@@ -2277,9 +2289,11 @@ class Input(Element):
2277
2289
  self.TKEntry.icursor(move_cursor_to)
2278
2290
  # since value changed, update the placeholder
2279
2291
  self.showing_placeholder = False # set to not showing so it'll get set up again if needed
2280
- self.TKEntry.config(fg=self.TextColor)
2281
- self.TKEntry.config(bg=self.BackgroundColor)
2292
+ self.TKEntry.config(fg=color_check(self.TextColor))
2293
+ self.TKEntry.config(bg=color_check(self.BackgroundColor))
2282
2294
  self.TKEntry.config(justify=self.tk_justify)
2295
+ # self.TKEntry.config(fg=self.TextColor)
2296
+ # self.TKEntry.config(bg=self.BackgroundColor)
2283
2297
  self.update_placeholder()
2284
2298
  if select is True:
2285
2299
  self.TKEntry.select_range(0, 'end')
@@ -2305,14 +2319,14 @@ class Input(Element):
2305
2319
  text = self.TKStringVar.get()
2306
2320
  if not self.mouse_over and not self.has_focus and text == '' and not self.showing_placeholder:
2307
2321
  self.TKStringVar.set(self.placeholder)
2308
- entry_widget.config(fg=self.placeholder_text_color if self.placeholder_text_color != COLOR_SYSTEM_DEFAULT else None)
2309
- entry_widget.config(bg=self.placeholder_background_color if self.placeholder_background_color != COLOR_SYSTEM_DEFAULT else None)
2322
+ entry_widget.config(fg=color_check(self.placeholder_text_color))
2323
+ entry_widget.config(bg=color_check(self.placeholder_background_color))
2310
2324
  entry_widget.config(justify=self.tk_justify_placeholder)
2311
2325
  self.showing_placeholder = True
2312
2326
  elif self.showing_placeholder and (self.mouse_over or self.has_focus):
2313
2327
  self.TKStringVar.set('')
2314
- entry_widget.config(fg=self.TextColor if self.TextColor != COLOR_SYSTEM_DEFAULT else None)
2315
- entry_widget.config(bg=self.BackgroundColor if self.TextColor != COLOR_SYSTEM_DEFAULT else None)
2328
+ entry_widget.config(fg=color_check(self.TextColor))
2329
+ entry_widget.config(bg=color_check(self.BackgroundColor))
2316
2330
  entry_widget.config(justify=self.tk_justify)
2317
2331
  self.showing_placeholder = False
2318
2332
 
@@ -3134,13 +3148,13 @@ class Listbox(Element):
3134
3148
  return
3135
3149
 
3136
3150
  if text_color is not None:
3137
- self.widget.itemconfig(index, fg=text_color)
3151
+ self.widget.itemconfig(index, fg=color_check(text_color))
3138
3152
  if background_color is not None:
3139
- self.widget.itemconfig(index, bg=background_color)
3153
+ self.widget.itemconfig(index, bg=color_check(background_color))
3140
3154
  if highlight_text_color is not None:
3141
- self.widget.itemconfig(index, selectforeground=highlight_text_color)
3155
+ self.widget.itemconfig(index, selectforeground=color_check(highlight_text_color))
3142
3156
  if highlight_background_color is not None:
3143
- self.widget.itemconfig(index, selectbackground=highlight_background_color)
3157
+ self.widget.itemconfig(index, selectbackground=color_check(highlight_background_color))
3144
3158
 
3145
3159
 
3146
3160
 
@@ -3305,11 +3319,11 @@ class Radio(Element):
3305
3319
  if text is not None:
3306
3320
  self.Text = str(text)
3307
3321
  self.TKRadio.configure(text=self.Text)
3308
- if background_color not in (None, COLOR_SYSTEM_DEFAULT):
3309
- self.TKRadio.configure(background=background_color)
3322
+ if background_color is not None:
3323
+ self.TKRadio.configure(bg=color_check(background_color))
3310
3324
  self.BackgroundColor = background_color
3311
- if text_color not in (None, COLOR_SYSTEM_DEFAULT):
3312
- self.TKRadio.configure(fg=text_color)
3325
+ if text_color is not None:
3326
+ self.TKRadio.configure(fg=color_check(text_color))
3313
3327
  self.TextColor = text_color
3314
3328
 
3315
3329
  if circle_color not in (None, COLOR_SYSTEM_DEFAULT):
@@ -3524,16 +3538,16 @@ class Checkbox(Element):
3524
3538
  if text is not None:
3525
3539
  self.Text = str(text)
3526
3540
  self.TKCheckbutton.configure(text=self.Text)
3527
- if background_color not in (None, COLOR_SYSTEM_DEFAULT):
3528
- self.TKCheckbutton.configure(background=background_color)
3541
+ if background_color is not None:
3542
+ self.TKCheckbutton.configure(bg=color_check(background_color))
3529
3543
  self.BackgroundColor = background_color
3530
- if text_color not in (None, COLOR_SYSTEM_DEFAULT):
3531
- self.TKCheckbutton.configure(fg=text_color)
3544
+ if text_color is not None:
3545
+ self.TKCheckbutton.configure(fg=color_check(text_color))
3532
3546
  self.TextColor = text_color
3533
3547
  # Color the checkbox itself
3534
3548
  if checkbox_color not in (None, COLOR_SYSTEM_DEFAULT):
3535
3549
  self.CheckboxBackgroundColor = checkbox_color
3536
- self.TKCheckbutton.configure(selectcolor=self.CheckboxBackgroundColor) # The background of the checkbox
3550
+ self.TKCheckbutton.configure(selectcolor=color_check(self.CheckboxBackgroundColor)) # The background of the checkbox
3537
3551
  elif text_color or background_color:
3538
3552
  if self.CheckboxBackgroundColor is not None and self.TextColor is not None and self.BackgroundColor is not None and self.TextColor.startswith(
3539
3553
  '#') and self.BackgroundColor.startswith('#'):
@@ -3546,7 +3560,7 @@ class Checkbox(Element):
3546
3560
  else:
3547
3561
  bg_rbg = _hsl_to_rgb(background_hsl[0], background_hsl[1], background_hsl[2] + l_delta)
3548
3562
  self.CheckboxBackgroundColor = rgb(*bg_rbg)
3549
- self.TKCheckbutton.configure(selectcolor=self.CheckboxBackgroundColor) # The background of the checkbox
3563
+ self.TKCheckbutton.configure(selectcolor=color_check(self.CheckboxBackgroundColor)) # The background of the checkbox
3550
3564
 
3551
3565
  if visible is False:
3552
3566
  self._pack_forget_save_settings()
@@ -4019,9 +4033,9 @@ class Multiline(Element):
4019
4033
  if tag not in self.tags:
4020
4034
  self.tags.add(tag)
4021
4035
  if background_color_for_value is not None:
4022
- self.TKText.tag_configure(tag, background=background_color_for_value)
4036
+ self.TKText.tag_configure(tag, background=color_check(background_color_for_value))
4023
4037
  if text_color_for_value is not None:
4024
- self.TKText.tag_configure(tag, foreground=text_color_for_value)
4038
+ self.TKText.tag_configure(tag, foreground=color_check(text_color_for_value))
4025
4039
  if font_for_value is not None:
4026
4040
  self.TKText.tag_configure(tag, font=font_for_value)
4027
4041
  except Exception as e:
@@ -4068,9 +4082,9 @@ class Multiline(Element):
4068
4082
  self.TKText.configure(state='normal')
4069
4083
  self.Disabled = disabled if disabled is not None else self.Disabled
4070
4084
 
4071
- if background_color not in (None, COLOR_SYSTEM_DEFAULT):
4072
- self.TKText.configure(background=background_color)
4073
- if text_color not in (None, COLOR_SYSTEM_DEFAULT):
4085
+ if background_color is not None:
4086
+ self.TKText.configure(bg=color_check(background_color))
4087
+ if text_color is not None:
4074
4088
  self.TKText.configure(fg=text_color)
4075
4089
  if font is not None:
4076
4090
  self.TKText.configure(font=font)
@@ -4244,7 +4258,7 @@ class Multiline(Element):
4244
4258
  return
4245
4259
  if ibeam_color is not None:
4246
4260
  try:
4247
- self.Widget.config(insertbackground=ibeam_color)
4261
+ self.Widget.config(insertbackground=color_check(ibeam_color))
4248
4262
  except Exception as e:
4249
4263
  _error_popup_with_traceback('Error setting I-Beam color in set_ibeam_color',
4250
4264
  'The element has a key:', self.Key,
@@ -4395,10 +4409,10 @@ class Text(Element):
4395
4409
  if value is not None:
4396
4410
  self.DisplayText = str(value)
4397
4411
  self.TKStringVar.set(str(value))
4398
- if background_color not in (None, COLOR_SYSTEM_DEFAULT):
4399
- self.TKText.configure(background=background_color)
4400
- if text_color not in (None, COLOR_SYSTEM_DEFAULT):
4401
- self.TKText.configure(fg=text_color)
4412
+ if background_color is not None:
4413
+ self.TKText.configure(bg=color_check(background_color))
4414
+ if text_color is not None:
4415
+ self.TKText.configure(fg=color_check(text_color))
4402
4416
  if font is not None:
4403
4417
  self.TKText.configure(font=font)
4404
4418
  if visible is False:
@@ -4740,10 +4754,10 @@ class StatusBar(Element):
4740
4754
  self.DisplayText = value
4741
4755
  stringvar = self.TKStringVar
4742
4756
  stringvar.set(value)
4743
- if background_color not in (None, COLOR_SYSTEM_DEFAULT):
4744
- self.TKText.configure(background=background_color)
4745
- if text_color not in (None, COLOR_SYSTEM_DEFAULT):
4746
- self.TKText.configure(fg=text_color)
4757
+ if background_color is not None:
4758
+ self.TKText.configure(bg=color_check(background_color))
4759
+ if text_color is not None:
4760
+ self.TKText.configure(fg=color_check(text_color))
4747
4761
  if font is not None:
4748
4762
  self.TKText.configure(font=font)
4749
4763
  if visible is False:
@@ -5439,18 +5453,14 @@ class Button(Element):
5439
5453
  self.TKButton.config(underline=pos)
5440
5454
  self.TKButton.configure(text=btext)
5441
5455
  self.ButtonText = text
5442
- if button_color != (None, None) and button_color != COLOR_SYSTEM_DEFAULT:
5456
+ if button_color != (None, None):
5443
5457
  bc = button_color_to_tuple(button_color, self.ButtonColor)
5444
5458
  if self.UseTtkButtons:
5445
- if bc[0] not in (None, COLOR_SYSTEM_DEFAULT):
5446
- button_style.configure(style_name, foreground=bc[0])
5447
- if bc[1] not in (None, COLOR_SYSTEM_DEFAULT):
5448
- button_style.configure(style_name, background=bc[1])
5459
+ button_style.configure(style_name, fg=color_check(bc[0]))
5460
+ button_style.configure(style_name, bg=color_check(bc[1]))
5449
5461
  else:
5450
- if bc[0] not in (None, COLOR_SYSTEM_DEFAULT):
5451
- self.TKButton.config(foreground=bc[0], activebackground=bc[0])
5452
- if bc[1] not in (None, COLOR_SYSTEM_DEFAULT):
5453
- self.TKButton.config(background=bc[1], activeforeground=bc[1])
5462
+ self.TKButton.config(fg=color_check(bc[0]), activebackground=color_check(bc[0]))
5463
+ self.TKButton.config(bg=color_check(bc[1]), activeforeground=color_check(bc[1]))
5454
5464
  self.ButtonColor = bc
5455
5465
  if disabled is True:
5456
5466
  self.TKButton['state'] = 'disabled'
@@ -5514,7 +5524,8 @@ class Button(Element):
5514
5524
  else:
5515
5525
  width, height = image.width(), image.height()
5516
5526
 
5517
- if self.TKButton.image is not None:
5527
+ # if self.TKButton.image is not None:
5528
+ if hasattr(self.TKButton, 'image') and self.TKButton.image is not None:
5518
5529
  del self.TKButton.image
5519
5530
  if self.UseTtkButtons:
5520
5531
  button_style.configure(style_name, borderwidth=0, image='', width=width, height=height) # clear previous image
@@ -5724,15 +5735,10 @@ class ButtonMenu(Element):
5724
5735
  if menu_definition is not None:
5725
5736
  self.MenuDefinition = copy.deepcopy(menu_definition)
5726
5737
  top_menu = self.TKMenu = tk.Menu(self.TKButtonMenu, tearoff=self.Tearoff, font=self.ItemFont, tearoffcommand=self._tearoff_menu_callback)
5727
-
5728
- if self.BackgroundColor not in (COLOR_SYSTEM_DEFAULT, None):
5729
- top_menu.config(bg=self.BackgroundColor)
5730
- if self.TextColor not in (COLOR_SYSTEM_DEFAULT, None):
5731
- top_menu.config(fg=self.TextColor)
5732
- if self.DisabledTextColor not in (COLOR_SYSTEM_DEFAULT, None):
5733
- top_menu.config(disabledforeground=self.DisabledTextColor)
5734
- if self.ItemFont is not None:
5735
- top_menu.config(font=self.ItemFont)
5738
+ top_menu.config(bg=color_check(self.BackgroundColor))
5739
+ top_menu.config(fg=color_check(self.TextColor))
5740
+ top_menu.config(disabledforeground=color_check_blank(self.DisabledTextColor))
5741
+ top_menu.config(font=self.ItemFont)
5736
5742
  AddMenuItem(self.TKMenu, self.MenuDefinition[1], self)
5737
5743
  self.TKButtonMenu.configure(menu=self.TKMenu)
5738
5744
  if image_source is not None:
@@ -5781,10 +5787,8 @@ class ButtonMenu(Element):
5781
5787
  self._visible = visible
5782
5788
  if button_color != (None, None) and button_color != COLOR_SYSTEM_DEFAULT:
5783
5789
  bc = button_color_to_tuple(button_color, self.ButtonColor)
5784
- if bc[0] not in (None, COLOR_SYSTEM_DEFAULT):
5785
- self.TKButtonMenu.config(foreground=bc[0], activeforeground=bc[0])
5786
- if bc[1] not in (None, COLOR_SYSTEM_DEFAULT):
5787
- self.TKButtonMenu.config(background=bc[1], activebackground=bc[1])
5790
+ self.TKButtonMenu.config(fg=color_check(bc[0]), activeforeground=color_check(bc[0]))
5791
+ self.TKButtonMenu.config(bg=color_check(bc[1]), activebackground=color_check(bc[1]))
5788
5792
  self.ButtonColor = bc
5789
5793
 
5790
5794
  def click(self):
@@ -5949,7 +5953,7 @@ class ProgressBar(Element):
5949
5953
  bar_color = _simplified_dual_color_to_tuple(bar_color, default=DEFAULT_PROGRESS_BAR_COLOR)
5950
5954
  self.BarColor = bar_color
5951
5955
  style = ttk.Style()
5952
- style.configure(self.ttk_style_name, background=bar_color[0], troughcolor=bar_color[1])
5956
+ style.configure(self.ttk_style_name, background=color_check(bar_color[0]), troughcolor=color_check(bar_color[1]))
5953
5957
  if current_count is not None:
5954
5958
  self.TKProgressBar.Update(current_count, max=max)
5955
5959
 
@@ -6079,22 +6083,22 @@ class Image(Element):
6079
6083
  function "pin" to ensure your element is "pinned" to that location in your layout so that it returns there
6080
6084
  when made visible.
6081
6085
 
6082
- :param source: A filename or a base64 bytes. Will automatically detect the type and fill in filename or data for you.
6083
- :type source: str | bytes | None
6084
- :param filename: filename to the new image to display.
6085
- :type filename: (str)
6086
- :param data: Base64 encoded string OR a tk.PhotoImage object
6087
- :type data: str | tkPhotoImage
6088
- :param mouseover_image_source: Image to show when the button is moused over. Note - must have an image set to use a mouseover button image
6089
- :type mouseover_image_source: (str | bytes)
6090
- :param size: (width, height) size of image in pixels
6091
- :type size: Tuple[int,int]
6092
- :param subsample: amount to reduce the size of the image. Divides the size by this number. 2=1/2, 3=1/3, 4=1/4, etc
6093
- :type subsample: (int)
6094
- :param zoom: amount to increase the size of the image
6095
- :type zoom: (int)
6096
- :param visible: control visibility of element
6097
- :type visible: (bool)
6086
+ :param source: A filename or a base64 bytes. Will automatically detect the type and fill in filename or data for you.
6087
+ :type source: str | bytes | None
6088
+ :param filename: filename to the new image to display.
6089
+ :type filename: (str)
6090
+ :param data: Base64 encoded string OR a tk.PhotoImage object
6091
+ :type data: str | tkPhotoImage
6092
+ :param mouseover_image_source: Image to show when the button is moused over. Note - must have an image set to use a mouseover button image
6093
+ :type mouseover_image_source: (str | bytes)
6094
+ :param size: (width, height) size of image in pixels
6095
+ :type size: Tuple[int,int]
6096
+ :param subsample: Amount to reduce the size of the image. Divides the size by this number. 2=1/2, 3=1/3, 4=1/4, etc
6097
+ :type subsample: (int)
6098
+ :param zoom: Amount to increase the size of the image
6099
+ :type zoom: (int)
6100
+ :param visible: Controls visibility of element
6101
+ :type visible: (bool)
6098
6102
  """
6099
6103
 
6100
6104
  if not self._widget_was_created(): # if widget hasn't been created yet, then don't allow
@@ -6200,9 +6204,9 @@ class Image(Element):
6200
6204
  width, height = image.width(), image.height()
6201
6205
 
6202
6206
  self.tktext_label.configure(image='') # clear previous image
6203
- if self.tktext_label.image is not None:
6204
- del self.tktext_label.image
6205
6207
 
6208
+ if hasattr(self.tktext_label, 'image') and self.tktext_label.image is not None:
6209
+ del self.tktext_label.image
6206
6210
  try: # sometimes crashes if user closed with X
6207
6211
  self.tktext_label.configure(image=image, width=width, height=height)
6208
6212
  except Exception as e:
@@ -6399,8 +6403,7 @@ class Canvas(Element):
6399
6403
  _error_popup_with_traceback('Error in Canvas.update - The window was closed')
6400
6404
  return
6401
6405
 
6402
- if background_color not in (None, COLOR_SYSTEM_DEFAULT):
6403
- self._TKCanvas.configure(background=background_color)
6406
+ self._TKCanvas.configure(bg=color_check(background_color))
6404
6407
  if visible is False:
6405
6408
  self._pack_forget_save_settings()
6406
6409
  elif visible is True:
@@ -6938,8 +6941,7 @@ class Graph(Element):
6938
6941
  _error_popup_with_traceback('Error in Graph.update - The window was closed')
6939
6942
  return
6940
6943
 
6941
- if background_color is not None and background_color != COLOR_SYSTEM_DEFAULT:
6942
- self._TKCanvas2.configure(background=background_color)
6944
+ self._TKCanvas2.configure(bg=color_check(background_color))
6943
6945
 
6944
6946
  if visible is False:
6945
6947
  self._pack_forget_save_settings()
@@ -7430,7 +7432,7 @@ class Frame(Element):
7430
7432
  if visible is not None:
7431
7433
  self._visible = visible
7432
7434
  if border_color is not None:
7433
- self.Widget.configure(highlightcolor=border_color , highlightbackground=border_color)
7435
+ self.Widget.configure(highlightcolor=color_check(border_color) , highlightbackground=color_check(border_color))
7434
7436
  self.BorderColor = border_color
7435
7437
 
7436
7438
  AddRow = add_row
@@ -7839,7 +7841,7 @@ class Tab(Element):
7839
7841
 
7840
7842
 
7841
7843
  self.tktext_label.configure(image='') # clear previous image
7842
- if self.tktext_label.image is not None:
7844
+ if hasattr(self.tktext_label, 'image') and self.tktext_label.image is not None:
7843
7845
  del self.tktext_label.image
7844
7846
 
7845
7847
  try: # sometimes crashes if user closed with X
@@ -8184,9 +8186,7 @@ class TabGroup(Element):
8184
8186
  tab_element.TabID = self.TabCount
8185
8187
  tab_element.ParentForm = self.ParentForm
8186
8188
  self.TabCount += 1
8187
- if tab_element.BackgroundColor != COLOR_SYSTEM_DEFAULT and tab_element.BackgroundColor is not None:
8188
- tab_element.TKFrame.configure(background=tab_element.BackgroundColor, highlightbackground=tab_element.BackgroundColor,
8189
- highlightcolor=tab_element.BackgroundColor)
8189
+ tab_element.TKFrame.configure(bg=color_check(tab_element.BackgroundColor), highlightbackground=color_check(tab_element.BackgroundColor), highlightcolor=color_check(tab_element.BackgroundColor))
8190
8190
  if tab_element.BorderWidth is not None:
8191
8191
  tab_element.TKFrame.configure(borderwidth=tab_element.BorderWidth)
8192
8192
  if tab_element.Tooltip is not None:
@@ -8501,6 +8501,17 @@ class TkScrollableFrame(tk.Frame):
8501
8501
  # Chr0nic
8502
8502
  def unhookMouseWheel(self, e):
8503
8503
  # print("leave")
8504
+ # A <Leave> also fires when the pointer moves onto a CHILD widget inside the scrolled frame (NotifyInferior crossing).
8505
+ # If the pointer is still inside this frame or any descendant, it is not a real leave - keep the wheel bindings hooked.
8506
+ if e is not None:
8507
+ try:
8508
+ widget = self.winfo_containing(*self.winfo_pointerxy())
8509
+ except Exception:
8510
+ widget = None
8511
+ while widget is not None:
8512
+ if widget == self:
8513
+ return
8514
+ widget = widget.master
8504
8515
  VarHolder.canvas_holder = None
8505
8516
  self.canvas.unbind_all('<4>')
8506
8517
  self.canvas.unbind_all('<5>')
@@ -8822,7 +8833,7 @@ class Pane(Element):
8822
8833
  """
8823
8834
 
8824
8835
  def __init__(self, pane_list, background_color=None, size=(None, None), s=(None, None), pad=None, p=None, orientation='vertical',
8825
- show_handle=True, relief=RELIEF_RAISED, handle_size=None, border_width=None, key=None, k=None, expand_x=None, expand_y=None, visible=True, metadata=None):
8836
+ show_handle=True, relief=RELIEF_RAISED, sash_cursor=None, sash_width=None, handle_size=None, border_width=None, key=None, k=None, expand_x=None, expand_y=None, visible=True, metadata=None):
8826
8837
  """
8827
8838
  :param pane_list: Must be a list of Column Elements. Each Column supplied becomes one pane that's shown
8828
8839
  :type pane_list: List[Column] | Tuple[Column]
@@ -8842,6 +8853,10 @@ class Pane(Element):
8842
8853
  :type show_handle: (bool)
8843
8854
  :param relief: relief style. Values are same as other elements that use relief values. RELIEF_RAISED RELIEF_SUNKEN RELIEF_FLAT RELIEF_RIDGE RELIEF_GROOVE RELIEF_SOLID
8844
8855
  :type relief: (str)
8856
+ :param sash_cursor: Type of cursor to show when the mouse is over the sash. Any Tk cursor works. Best to use: sb_v_double_arrow, sb_h_double_arrow
8857
+ :type sash_cursor: (str)
8858
+ :param sash_width: Width of the sash in pixels
8859
+ :type sash_width: (int)
8845
8860
  :param handle_size: Size of the handle in pixels
8846
8861
  :type handle_size: (int)
8847
8862
  :param border_width: width of border around element in pixels
@@ -8874,6 +8889,8 @@ class Pane(Element):
8874
8889
  self.ShowHandle = show_handle
8875
8890
  self.Relief = relief
8876
8891
  self.HandleSize = handle_size or 8
8892
+ self.SashWidth = sash_width
8893
+ self.SashCursor = sash_cursor
8877
8894
  self.BorderDepth = border_width
8878
8895
  bg = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
8879
8896
 
@@ -8987,7 +9004,6 @@ class Menu(Element):
8987
9004
 
8988
9005
  super().__init__(ELEM_TYPE_MENUBAR, background_color=self.BackgroundColor, text_color=self.TextColor, size=sz, pad=pad, key=key, visible=visible,
8989
9006
  font=font, metadata=metadata)
8990
- # super().__init__(ELEM_TYPE_MENUBAR, background_color=COLOR_SYSTEM_DEFAULT, text_color=COLOR_SYSTEM_DEFAULT, size=sz, pad=pad, key=key, visible=visible, font=None, metadata=metadata)
8991
9007
 
8992
9008
  self.Tearoff = tearoff
8993
9009
 
@@ -9041,17 +9057,11 @@ class Menu(Element):
9041
9057
  for menu_entry in self.MenuDefinition:
9042
9058
  baritem = tk.Menu(menubar, tearoff=self.Tearoff, tearoffcommand=self._tearoff_menu_callback)
9043
9059
 
9044
- if self.BackgroundColor not in (COLOR_SYSTEM_DEFAULT, None):
9045
- baritem.config(bg=self.BackgroundColor)
9046
- if self.TextColor not in (COLOR_SYSTEM_DEFAULT, None):
9047
- baritem.config(fg=self.TextColor)
9048
- if self.DisabledTextColor not in (COLOR_SYSTEM_DEFAULT, None):
9049
- baritem.config(disabledforeground=self.DisabledTextColor)
9050
- if self.Font is not None:
9051
- baritem.config(font=self.Font)
9052
-
9053
- if self.Font is not None:
9054
- baritem.config(font=self.Font)
9060
+ baritem.config(bg=color_check(self.BackgroundColor))
9061
+ baritem.config(fg=color_check(self.TextColor))
9062
+ baritem.config(disabledforeground=color_check_blank(self.DisabledTextColor))
9063
+ baritem.config(font=self.Font)
9064
+
9055
9065
  pos = menu_entry[0].find(MENU_SHORTCUT_CHARACTER)
9056
9066
  # print(pos)
9057
9067
  if pos != -1:
@@ -9066,10 +9076,15 @@ class Menu(Element):
9066
9076
  if len(menu_entry) > 1:
9067
9077
  AddMenuItem(baritem, menu_entry[1], self)
9068
9078
 
9079
+ root = self.ParentForm.TKroot
9080
+ cur_w, cur_h = root.winfo_width(), root.winfo_height() # client size before the menubar change
9069
9081
  if visible is False:
9070
- self.ParentForm.TKroot.configure(menu=[]) # this will cause the menubar to disappear
9082
+ root.configure(menu=[]) # this will cause the menubar to disappear
9071
9083
  elif self.TKMenu is not None:
9072
- self.ParentForm.TKroot.configure(menu=self.TKMenu)
9084
+ root.configure(menu=self.TKMenu)
9085
+ root.update_idletasks()
9086
+ if (root.winfo_width(), root.winfo_height()) != (cur_w, cur_h): # Windows grows the client by the menubar height when the bar is removed from a window created with the 6.3.11 withdraw method - snap it back
9087
+ root.geometry('{}x{}'.format(cur_w, cur_h))
9073
9088
  if visible is not None:
9074
9089
  self._visible = visible
9075
9090
 
@@ -9364,14 +9379,14 @@ class Table(Element):
9364
9379
 
9365
9380
  if self.AlternatingRowColor is not None:
9366
9381
  for row in range(0, len(self.Values), 2):
9367
- self.TKTreeview.tag_configure(row, background=self.AlternatingRowColor)
9382
+ self.TKTreeview.tag_configure(row, background=color_check(self.AlternatingRowColor))
9368
9383
  if row_colors is not None: # individual row colors
9369
9384
  self.RowColors = row_colors
9370
9385
  for row_def in self.RowColors:
9371
9386
  if len(row_def) == 2: # only background is specified
9372
- self.TKTreeview.tag_configure(row_def[0], background=row_def[1])
9387
+ self.TKTreeview.tag_configure(row_def[0], background=color_check(row_def[1]))
9373
9388
  else:
9374
- self.TKTreeview.tag_configure(row_def[0], background=row_def[2], foreground=row_def[1])
9389
+ self.TKTreeview.tag_configure(row_def[0], background=color_check(row_def[2]), foreground=color_check(row_def[1]))
9375
9390
  if visible is not None:
9376
9391
  self._visible = visible
9377
9392
 
@@ -10223,7 +10238,7 @@ class Window:
10223
10238
  _rerouted_stderr_stack = [] # type: List[Tuple[Window, Element]]
10224
10239
  _original_stdout = None
10225
10240
  _original_stderr = None
10226
-
10241
+ _set_tooltip_to_element_key = DEFAULT_SET_TOOLTIP_TO_ELEMENT_KEY
10227
10242
 
10228
10243
  def __init__(self, title, layout=None, default_element_size=None,
10229
10244
  default_button_element_size=(None, None),
@@ -10259,7 +10274,7 @@ class Window:
10259
10274
  :param location: (x,y) location, in pixels, to locate the upper left corner of the window on the screen. Default is to center on screen. None will not set any location meaning the OS will decide
10260
10275
  :type location: (int, int) or (None, None) or None
10261
10276
  :param location_anchor: Position on a window that is used to achnor the widow to a location. Default = WIN_ANCHOR_UPPER_LEFT if location is specified
10262
- :type location_anchor: (str)
10277
+ :type location_anchor: str | None
10263
10278
  :param relative_location: (x,y) location relative to the default location of the window, in pixels. This location is relative to the location the window would be created. Note they can be negative.
10264
10279
  :type relative_location: (int, int) | (None, None)
10265
10280
  :param auto_save_location: If True the windows location will be automatically saved to a settings file and will be reloaded next time the program is run. Save happens when window close is detected
@@ -10304,8 +10319,8 @@ class Window:
10304
10319
  :type grab_anywhere_using_control: (bool)
10305
10320
  :param keep_on_top: If True, window will be created on top of all other windows on screen. It can be bumped down if another window created with this parm
10306
10321
  :type keep_on_top: (bool)
10307
- :param resizable: If True, allows the user to resize the window. Note the not all Elements will change size or location when resizing.
10308
- :type resizable: (bool)
10322
+ :param resizable: If True, allows the user to resize the window. If a (bool, bool) TUPLE - resizing can be controlled for each direction (x, y) Expansion parameter for elements determine how they resize.
10323
+ :type resizable: bool | (str, str)
10309
10324
  :param use_min_size: If True the window's minimum size will be set when the window is created
10310
10325
  :type use_min_size: (bool)
10311
10326
  :param disable_close: If True, the X button in the top right corner of the window will no work. Use with caution and always give a way out toyour users
@@ -10526,9 +10541,12 @@ class Window:
10526
10541
  self._mousex = self._mousey = 0
10527
10542
  self._startx = self._starty = 0
10528
10543
  self._last_location = (None, None) # used by a property
10544
+ self._frame_extents = None # (left, top) size of OS titlebar/border, measured once the WM has framed the window
10529
10545
  self.auto_save_location = auto_save_location
10530
10546
  if auto_save_location is True:
10531
- self.Location = user_settings_get_entry('-LAST WINDOW LOCATION-'+title, self.Location)
10547
+ saved_location = tuple(user_settings_get_entry('-LAST WINDOW LOCATION-'+title, self.Location))
10548
+ if saved_location != (None, None):
10549
+ self.Location = saved_location
10532
10550
  self.scaling = scaling if scaling is not None else DEFAULT_SCALING
10533
10551
 
10534
10552
  if self.use_custom_titlebar:
@@ -11084,6 +11102,7 @@ class Window:
11084
11102
  self._start_autoclose_timer()
11085
11103
  self.auto_close_timer_needs_starting = False
11086
11104
 
11105
+ self._measure_frame_extents() # no-op once measured; ensures it happens even if no <Configure> arrives after the binding
11087
11106
  timeout = int(timeout) if timeout is not None else None
11088
11107
  if timeout == 0: # timeout of zero runs the old readnonblocking
11089
11108
  event, values = self._ReadNonBlocking()
@@ -11832,9 +11851,12 @@ class Window:
11832
11851
  :type event: Any
11833
11852
  """
11834
11853
  # do the location auto-save stuff. If the location changes, then the location is written to the settings file
11854
+ self._measure_frame_extents() # learns titlebar/border size once the WM has framed the window (no-op after that)
11835
11855
  if self.auto_save_location:
11836
11856
  try:
11837
- cur_location = self.current_location()
11857
+ # Save the FRAME corner - what location= / geometry("+x+y") restores. winfo_x/y is the CLIENT corner on Linux/X11 (window crept
11858
+ # down by the titlebar height each run) and Tk's geometry() read-back drifts under Cinnamon/Muffin once the window has been moved.
11859
+ cur_location = self.current_frame_location()
11838
11860
  old_location = self._last_location
11839
11861
  if None not in cur_location:
11840
11862
  self._last_location= cur_location
@@ -12053,6 +12075,14 @@ class Window:
12053
12075
  :return:
12054
12076
  """
12055
12077
  if self.auto_save_location:
12078
+ try: # take a fresh reading if the window is still alive - it may be better calibrated than the last <Configure> value
12079
+ if self.TKroot.winfo_exists() and self.TKroot.state() == 'normal':
12080
+ self._measure_frame_extents()
12081
+ location = self.current_frame_location()
12082
+ if None not in location:
12083
+ self._last_location = location
12084
+ except Exception:
12085
+ pass
12056
12086
  user_settings_set_entry('-LAST WINDOW LOCATION-'+self.Title, self._last_location)
12057
12087
 
12058
12088
 
@@ -12254,6 +12284,9 @@ class Window:
12254
12284
  Thus, the values can appear top be "off" due to the sometimes unpredictable way the location is calculated.
12255
12285
  If without_titlebar is set then the location of the root x,y is used which should not include the titlebar but
12256
12286
  may be OS dependent.
12287
+ NOTE: on Linux/X11 the default (winfo_x/y) returns the CLIENT corner (same as without_titlebar=True); on Windows it returns the FRAME corner.
12288
+ more_accurate=True is Tk's idea of the frame corner; on Cinnamon/Muffin it drifts from the real one once the window has been moved.
12289
+ To get a value that can be fed back into location= / move() use Window.current_frame_location(). See also Window.frame_extents().
12257
12290
 
12258
12291
  :param more_accurate: If True, will use the window's geometry to get the topmost location with titlebar, menubar taken into account
12259
12292
  :type more_accurate: (bool)
@@ -12312,6 +12345,66 @@ class Window:
12312
12345
  x, y = (None, None)
12313
12346
  return (x,y)
12314
12347
 
12348
+ def _measure_frame_extents(self):
12349
+ """
12350
+ Learns the size of the OS decorations ONCE: client corner (winfo_rootx/rooty) minus the frame position PySimpleGUI asked for
12351
+ (config_last_location). Called from <Configure> events and read(). On Linux the first events arrive before the window manager has
12352
+ framed the window (top measures 0) so it keeps trying until a titlebar is seen. The requested position is used instead of Tk's
12353
+ geometry() read-back because Cinnamon/Muffin includes its invisible resize borders in that once the window has been moved (off by ~10px).
12354
+ """
12355
+ if self._frame_extents is not None:
12356
+ return
12357
+ if self.NoTitleBar:
12358
+ self._frame_extents = (0, 0)
12359
+ return
12360
+ try:
12361
+ req_x, req_y = self.config_last_location
12362
+ if req_x is None or req_y is None:
12363
+ return
12364
+ left, top = self.TKroot.winfo_rootx() - req_x, self.TKroot.winfo_rooty() - req_y
12365
+ if top <= 0: # WM has not framed the window yet - try again on the next <Configure> / read
12366
+ return
12367
+ if not (0 <= left <= 64 and top <= 128): # WM ignored the requested position (tiling WM, forced placement) - use Tk's estimate
12368
+ frame_x, frame_y = self.current_location(more_accurate=True)
12369
+ left, top = max(self.TKroot.winfo_rootx() - frame_x, 0), max(self.TKroot.winfo_rooty() - frame_y, 0)
12370
+ self._frame_extents = (left, top)
12371
+ except Exception:
12372
+ pass
12373
+
12374
+ def current_frame_location(self):
12375
+ """
12376
+ Location of the frame corner (titlebar included) = the value to give location= or move() to put the window back exactly here.
12377
+ Client corner minus the measured decorations. Falls back to Tk's geometry() read-back until the decorations have been measured.
12378
+ current_location() is unchanged: on Windows it returns this same frame corner, on Linux/X11 it returns the client corner.
12379
+
12380
+ :return: (x, y) or (None, None)
12381
+ :rtype: Tuple[int, int] | Tuple[None, None]
12382
+ """
12383
+ if self._frame_extents is None:
12384
+ return self.current_location(more_accurate=True)
12385
+ try:
12386
+ return (self.TKroot.winfo_rootx() - self._frame_extents[0], self.TKroot.winfo_rooty() - self._frame_extents[1])
12387
+ except Exception:
12388
+ return (None, None)
12389
+
12390
+ def frame_extents(self):
12391
+ """
12392
+ Size in pixels of the decorations the OS / window manager adds around the window (titlebar + borders).
12393
+ Measured once, from the first <Configure> event or read() after the window manager has framed the window, as client corner
12394
+ (winfo_rootx/rooty) minus the frame position that was requested. tkinter cannot see the right/bottom edges, so they are assumed equal to left.
12395
+ Before the window is framed, or for no_titlebar windows, (0, 0, 0, 0) is returned. Works on Windows, Linux (X11 & XWayland) and macOS.
12396
+
12397
+ :return: (left, top, right, bottom). top = titlebar height (+ top border)
12398
+ :rtype: Tuple[int, int, int, int]
12399
+ """
12400
+ if not self._is_window_created('tried Window.frame_extents') or self.NoTitleBar:
12401
+ return (0, 0, 0, 0)
12402
+ self._measure_frame_extents()
12403
+ if self._frame_extents is None:
12404
+ return (0, 0, 0, 0)
12405
+ left, top = self._frame_extents
12406
+ return (left, top, left, left)
12407
+
12315
12408
  @property
12316
12409
  def size(self):
12317
12410
  """
@@ -12744,7 +12837,8 @@ class Window:
12744
12837
  if widget != self.TKroot:
12745
12838
  return
12746
12839
  self.TKRightClickMenu.tk_popup(event.x_root, event.y_root, 0)
12747
- self.TKRightClickMenu.grab_release()
12840
+ if not running_linux():
12841
+ self.TKRightClickMenu.grab_release()
12748
12842
 
12749
12843
  def save_window_screenshot_to_disk(self, filename=None):
12750
12844
  """
@@ -12770,14 +12864,14 @@ class Window:
12770
12864
  return None
12771
12865
  try:
12772
12866
  # Get location of window to save
12773
- pos = self.current_location()
12867
+ pos = self.current_frame_location() # same as current_location() on Windows; on Linux current_location() is the client corner
12774
12868
  # Add a little to the X direction if window has a titlebar
12775
12869
  if not self.NoTitleBar:
12776
12870
  pos = (pos[0] + 7, pos[1])
12777
12871
  # Get size of wiondow
12778
12872
  size = self.current_size_accurate()
12779
12873
  # Get size of the titlebar
12780
- titlebar_height = self.TKroot.winfo_rooty() - self.TKroot.winfo_y()
12874
+ titlebar_height = self.frame_extents()[1] # rooty - winfo_y is 0 on Linux/X11; frame_extents works everywhere
12781
12875
  # Add titlebar to size of window so that titlebar and window will be saved
12782
12876
  size = (size[0], size[1] + titlebar_height)
12783
12877
  if not self.NoTitleBar:
@@ -12884,18 +12978,20 @@ class Window:
12884
12978
 
12885
12979
  def _custom_titlebar_restore(self):
12886
12980
  if running_linux():
12887
- # if self._skip_first_restore_callback:
12888
- # self._skip_first_restore_callback = False
12889
- # return
12890
12981
  self.TKroot.unbind('<Button-1>')
12891
12982
  self.TKroot.deiconify()
12892
12983
 
12893
- # self.ParentForm.TKroot.wm_overrideredirect(True)
12894
12984
  self.TKroot.wm_attributes("-type", 'dock')
12895
-
12896
12985
  else:
12897
12986
  self.TKroot.unbind('<Expose>')
12898
- self.TKroot.wm_overrideredirect(True)
12987
+ if running_windows():
12988
+ self.TKroot.withdraw() # hide first: the wrapper Tk rebuilds on the next line is then created hidden
12989
+ self.TKroot.wm_overrideredirect(True) # Tk destroys/recreates the wrapper HWND, again with WS_EX_TOOLWINDOW (= no taskbar button)
12990
+ self.TKroot.attributes('-alpha', 1 if self.AlphaChannel is None else self.AlphaChannel) # Tk rewrites the ex-style with only its own bits -> TOOLWINDOW gone
12991
+ self.TKroot.deiconify() # hidden -> shown is when the shell re-reads the style. Same sequence that gives the icon at creation
12992
+ else:
12993
+ self.TKroot.wm_overrideredirect(True)
12994
+
12899
12995
  if self.TKroot.state() == 'iconic':
12900
12996
  self.TKroot.deiconify()
12901
12997
  else:
@@ -12908,12 +13004,7 @@ class Window:
12908
13004
  def _custom_titlebar_minimize(self):
12909
13005
  if running_linux():
12910
13006
  self.TKroot.wm_attributes("-type", "normal")
12911
- # self.ParentForm.TKroot.state('icon')
12912
- # return
12913
- # self.ParentForm.maximize()
12914
13007
  self.TKroot.wm_overrideredirect(False)
12915
- # self.ParentForm.minimize()
12916
- # self.ParentForm.TKroot.wm_overrideredirect(False)
12917
13008
  self.TKroot.iconify()
12918
13009
  # self._skip_first_restore_callback = True
12919
13010
  self.TKroot.bind('<Button-1>', self._custom_titlebar_restore_callback)
@@ -13232,7 +13323,11 @@ def read_all_windows(timeout=None, timeout_key=TIMEOUT_KEY):
13232
13323
  Window._TKAfterID = Window.hidden_master_root.after(timeout, _timeout_alarm_callback_hidden)
13233
13324
 
13234
13325
  # ------------ Call Mainloop ------------
13235
- Window._root_running_mainloop.mainloop()
13326
+ try:
13327
+ Window._root_running_mainloop.mainloop()
13328
+ except KeyboardInterrupt:
13329
+ print('KeyboardInterrupt detected in read_all_windows... exiting application')
13330
+ sys.exit()
13236
13331
 
13237
13332
  try:
13238
13333
  Window.hidden_master_root.after_cancel(Window._TKAfterID)
@@ -15704,37 +15799,27 @@ def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False,
15704
15799
  # if a right click menu, then get styling from the top-level window
15705
15800
  if right_click_menu:
15706
15801
  window = element.ParentForm
15707
- if window.right_click_menu_background_color not in (COLOR_SYSTEM_DEFAULT, None):
15708
- new_menu.config(bg=window.right_click_menu_background_color)
15709
- new_menu.config(activeforeground=window.right_click_menu_background_color)
15710
- if window.right_click_menu_text_color not in (COLOR_SYSTEM_DEFAULT, None):
15711
- new_menu.config(fg=window.right_click_menu_text_color)
15712
- new_menu.config(activebackground=window.right_click_menu_text_color)
15713
- if window.right_click_menu_disabled_text_color not in (COLOR_SYSTEM_DEFAULT, None):
15714
- new_menu.config(disabledforeground=window.right_click_menu_disabled_text_color)
15715
- if window.right_click_menu_font is not None:
15716
- new_menu.config(font=window.right_click_menu_font)
15802
+ new_menu.config(bg=color_check(window.right_click_menu_background_color))
15803
+ new_menu.config(activeforeground=color_check(window.right_click_menu_background_color))
15804
+ new_menu.config(fg=color_check(window.right_click_menu_text_color))
15805
+ new_menu.config(activebackground=color_check(window.right_click_menu_text_color))
15806
+ new_menu.config(disabledforeground=color_check_blank(window.right_click_menu_disabled_text_color))
15807
+ new_menu.config(font=window.right_click_menu_font)
15717
15808
  else:
15718
- if element.Font is not None:
15719
- new_menu.config(font=element.Font)
15720
- if element.BackgroundColor not in (COLOR_SYSTEM_DEFAULT, None):
15721
- new_menu.config(bg=element.BackgroundColor)
15722
- new_menu.config(activeforeground=element.BackgroundColor)
15723
- if element.TextColor not in (COLOR_SYSTEM_DEFAULT, None):
15724
- new_menu.config(fg=element.TextColor)
15725
- new_menu.config(activebackground=element.TextColor)
15726
- if element.DisabledTextColor not in (COLOR_SYSTEM_DEFAULT, None):
15727
- new_menu.config(disabledforeground=element.DisabledTextColor)
15728
- if element.ItemFont is not None:
15729
- new_menu.config(font=element.ItemFont)
15809
+ new_menu.config(font=element.Font)
15810
+ new_menu.config(bg=color_check(element.BackgroundColor))
15811
+ new_menu.config(activeforeground=color_check(element.BackgroundColor))
15812
+ new_menu.config(fg=color_check(element.TextColor))
15813
+ new_menu.config(activebackground=color_check(element.TextColor))
15814
+ new_menu.config(disabledforeground=color_check_blank(element.DisabledTextColor))
15815
+ new_menu.config(font=element.ItemFont)
15730
15816
  return_val = new_menu
15731
15817
  pos = sub_menu_info[i].find(MENU_SHORTCUT_CHARACTER)
15732
15818
  if pos != -1:
15733
15819
  if pos < len(MENU_SHORTCUT_CHARACTER) or sub_menu_info[i][pos - len(MENU_SHORTCUT_CHARACTER)] != "\\":
15734
15820
  sub_menu_info[i] = sub_menu_info[i][:pos] + sub_menu_info[i][pos + len(MENU_SHORTCUT_CHARACTER):]
15735
15821
  if sub_menu_info[i][0] == MENU_DISABLED_CHARACTER:
15736
- top_menu.add_cascade(label=sub_menu_info[i][len(MENU_DISABLED_CHARACTER):], menu=new_menu,
15737
- underline=pos, state='disabled')
15822
+ top_menu.add_cascade(label=sub_menu_info[i][len(MENU_DISABLED_CHARACTER):], menu=new_menu, underline=pos, state='disabled')
15738
15823
  else:
15739
15824
  top_menu.add_cascade(label=sub_menu_info[i], menu=new_menu, underline=pos)
15740
15825
  AddMenuItem(new_menu, sub_menu_info[i + 1], element, is_sub_menu=True, right_click_menu=right_click_menu)
@@ -15771,6 +15856,57 @@ class VarHolder(object):
15771
15856
 
15772
15857
  # ======================== TK CODE STARTS HERE ========================================= #
15773
15858
 
15859
+ def _is_valid_color(color):
15860
+ """
15861
+ Checks with tkinter to see if the color is a valid color. Will show an error if invalid and return False
15862
+ :param color: The color to test. Color string with name or #RRGGBB
15863
+ :type color: str
15864
+ :return: If tkinter says color is valid
15865
+ :rtype: cool
15866
+ """
15867
+ root = _get_hidden_master_root()
15868
+ try:
15869
+ root.winfo_rgb(color)
15870
+ except tk.TclError:
15871
+ popup_error_with_traceback(f'tkinter returned an error validating the color "{color}"')
15872
+ return False
15873
+ return True
15874
+
15875
+
15876
+ def color_check(color):
15877
+ """
15878
+ Checks a color for system default sentinel before sending to tkinter.
15879
+ If color is COLOR_SYSTEM_DEFAULT then can't send it to tkinter and need to
15880
+ instead send None. In some cases "" needs to be used instead of None (e.g. selectforeground)
15881
+
15882
+ :param color: The color to test. Color string with name or #RRGGBB
15883
+ :type color: str
15884
+ :return: The corrected color. Normally will be the same as color passed in
15885
+ :rtype: str | None
15886
+ """
15887
+ if color in (None, COLOR_SYSTEM_DEFAULT) or not _is_valid_color(color):
15888
+ return None
15889
+ else:
15890
+ return color
15891
+
15892
+
15893
+ def color_check_blank(color):
15894
+ """
15895
+ Checks a color for system default sentinel before sending to tkinter.
15896
+ If color is COLOR_SYSTEM_DEFAULT, returns "" instead, for options like
15897
+ selectforeground where Tk expects an empty string (not None) to mean default.
15898
+
15899
+ :param color: The color to test. Color string with name or #RRGGBB
15900
+ :type color: str
15901
+ :return: The corrected color. Normally will be the same as color passed in
15902
+ :rtype: str
15903
+ """
15904
+ if color in (COLOR_SYSTEM_DEFAULT, None) or not _is_valid_color(color):
15905
+ return ""
15906
+ else:
15907
+ return color
15908
+
15909
+
15774
15910
  def _widget_was_created(widget):
15775
15911
  """
15776
15912
  Determines if a Widget was created.
@@ -15795,56 +15931,56 @@ def _widget_was_created(widget):
15795
15931
  return False
15796
15932
 
15797
15933
 
15798
- def _widget_set_fg_color(widget, fg_color=None):
15799
- """
15800
- Sets the foreground color for a tkinter widget.
15801
- :param widget: The tkinter widget (should be non-ttk) to change
15802
- :type widget: tk.Widget
15803
- :param fg_color: The new color. Note that the magic number COLOR_SYSTEM_DEFAULT means no color will be changed/set. Should be a color name or hex string
15804
- :type fg_color: str
15805
- :return: Returns True is the color was able to be changed (False returns on any kind of error)
15806
- :rtype: bool
15807
- """
15808
-
15809
- if fg_color is None or fg_color == COLOR_SYSTEM_DEFAULT:
15810
- return False
15811
-
15812
- if not _widget_was_created(widget):
15813
- return False
15814
-
15815
- try:
15816
- widget.configure(fg=fg_color)
15817
- except Exception as e:
15818
- popup_error_with_traceback('Error setting tkinter widget foreground color',f'tkinter returned an error while attempting to set foreground color to "{fg_color}"',e)
15819
- return False
15820
- return True
15821
-
15822
-
15823
- def _widget_set_bg_color(widget, bg_color=None):
15824
- """
15825
- Sets the background color for a tkinter widget.
15826
- :param widget: The tkinter widget (should be non-ttk) to change
15827
- :type widget: tk.Widget
15828
- :param bg_color: The new color. Note that the magic number COLOR_SYSTEM_DEFAULT means no color will be changed/set
15829
- :type bg_color: str
15830
- :return: Returns True is the color was able to be changed (False returns on any kind of error)
15831
- :rtype: bool
15832
- """
15833
-
15834
-
15835
- if bg_color is None or bg_color == COLOR_SYSTEM_DEFAULT:
15836
- return False
15837
-
15838
- if not _widget_was_created(widget):
15839
- return False
15840
-
15841
- try:
15842
- widget.configure(bg=bg_color)
15843
- except Exception as e:
15844
- popup_error_with_traceback('Error setting tkinter widget background color',f'tkinter returned an error while attempting to set background color to "{bg_color}"', e)
15845
- return False
15846
-
15847
- return True
15934
+ # def _widget_set_fg_color(widget, fg_color=None):
15935
+ # """
15936
+ # Sets the foreground color for a tkinter widget.
15937
+ # :param widget: The tkinter widget (should be non-ttk) to change
15938
+ # :type widget: tk.Widget
15939
+ # :param fg_color: The new color. Note that the magic number COLOR_SYSTEM_DEFAULT means no color will be changed/set. Should be a color name or hex string
15940
+ # :type fg_color: str
15941
+ # :return: Returns True is the color was able to be changed (False returns on any kind of error)
15942
+ # :rtype: bool
15943
+ # """
15944
+ #
15945
+ # if fg_color is None or fg_color == COLOR_SYSTEM_DEFAULT:
15946
+ # return False
15947
+ #
15948
+ # if not _widget_was_created(widget):
15949
+ # return False
15950
+ #
15951
+ # try:
15952
+ # widget.configure(fg=fg_color)
15953
+ # except Exception as e:
15954
+ # popup_error_with_traceback('Error setting tkinter widget foreground color',f'tkinter returned an error while attempting to set foreground color to "{fg_color}"',e)
15955
+ # return False
15956
+ # return True
15957
+ #
15958
+ #
15959
+ # def _widget_set_bg_color(widget, bg_color=None):
15960
+ # """
15961
+ # Sets the background color for a tkinter widget.
15962
+ # :param widget: The tkinter widget (should be non-ttk) to change
15963
+ # :type widget: tk.Widget
15964
+ # :param bg_color: The new color. Note that the magic number COLOR_SYSTEM_DEFAULT means no color will be changed/set
15965
+ # :type bg_color: str
15966
+ # :return: Returns True is the color was able to be changed (False returns on any kind of error)
15967
+ # :rtype: bool
15968
+ # """
15969
+ #
15970
+ #
15971
+ # if bg_color is None or bg_color == COLOR_SYSTEM_DEFAULT:
15972
+ # return False
15973
+ #
15974
+ # if not _widget_was_created(widget):
15975
+ # return False
15976
+ #
15977
+ # try:
15978
+ # widget.configure(bg=bg_color)
15979
+ # except Exception as e:
15980
+ # popup_error_with_traceback('Error setting tkinter widget background color',f'tkinter returned an error while attempting to set background color to "{bg_color}"', e)
15981
+ # return False
15982
+ #
15983
+ # return True
15848
15984
 
15849
15985
 
15850
15986
  def _fixed_map(style, style_name, option, highlight_colors=(None, None)):
@@ -15868,19 +16004,13 @@ def _add_right_click_menu(element, toplevel_form):
15868
16004
  menu = element.RightClickMenu or toplevel_form.RightClickMenu
15869
16005
  top_menu = tk.Menu(toplevel_form.TKroot, tearoff=toplevel_form.right_click_menu_tearoff, tearoffcommand=element._tearoff_menu_callback)
15870
16006
 
15871
- if toplevel_form.right_click_menu_background_color not in (COLOR_SYSTEM_DEFAULT, None):
15872
- top_menu.config(bg=toplevel_form.right_click_menu_background_color)
15873
- if toplevel_form.right_click_menu_text_color not in (COLOR_SYSTEM_DEFAULT, None):
15874
- top_menu.config(fg=toplevel_form.right_click_menu_text_color)
15875
- if toplevel_form.right_click_menu_disabled_text_color not in (COLOR_SYSTEM_DEFAULT, None):
15876
- top_menu.config(disabledforeground=toplevel_form.right_click_menu_disabled_text_color)
15877
- if toplevel_form.right_click_menu_font is not None:
15878
- top_menu.config(font=toplevel_form.right_click_menu_font)
16007
+ top_menu.config(bg=color_check(toplevel_form.right_click_menu_background_color))
16008
+ top_menu.config(fg=color_check(toplevel_form.right_click_menu_text_color))
16009
+ top_menu.config(disabledforeground=color_check_blank(toplevel_form.right_click_menu_disabled_text_color))
16010
+ top_menu.config(font=toplevel_form.right_click_menu_font)
15879
16011
 
15880
- if toplevel_form.right_click_menu_selected_colors[0] not in (COLOR_SYSTEM_DEFAULT, None):
15881
- top_menu.config(activeforeground=toplevel_form.right_click_menu_selected_colors[0])
15882
- if toplevel_form.right_click_menu_selected_colors[1] not in (COLOR_SYSTEM_DEFAULT, None):
15883
- top_menu.config(activebackground=toplevel_form.right_click_menu_selected_colors[1])
16012
+ top_menu.config(activeforeground=color_check(toplevel_form.right_click_menu_selected_colors[0]))
16013
+ top_menu.config(activebackground=color_check(toplevel_form.right_click_menu_selected_colors[1]))
15884
16014
  AddMenuItem(top_menu, menu[1], element, right_click_menu=True)
15885
16015
  element.TKRightClickMenu = top_menu
15886
16016
  element.RightClickMenu = menu # Store the menu in the element in case the window was the source
@@ -16143,19 +16273,13 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
16143
16273
  if menu:
16144
16274
  top_menu = tk.Menu(toplevel_form.TKroot, tearoff=toplevel_form.right_click_menu_tearoff, tearoffcommand=element._tearoff_menu_callback)
16145
16275
 
16146
- if toplevel_form.right_click_menu_background_color not in (COLOR_SYSTEM_DEFAULT, None):
16147
- top_menu.config(bg=toplevel_form.right_click_menu_background_color)
16148
- if toplevel_form.right_click_menu_text_color not in (COLOR_SYSTEM_DEFAULT, None):
16149
- top_menu.config(fg=toplevel_form.right_click_menu_text_color)
16150
- if toplevel_form.right_click_menu_disabled_text_color not in (COLOR_SYSTEM_DEFAULT, None):
16151
- top_menu.config(disabledforeground=toplevel_form.right_click_menu_disabled_text_color)
16152
- if toplevel_form.right_click_menu_font is not None:
16153
- top_menu.config(font=toplevel_form.right_click_menu_font)
16154
-
16155
- if toplevel_form.right_click_menu_selected_colors[0] not in (COLOR_SYSTEM_DEFAULT, None):
16156
- top_menu.config(activeforeground=toplevel_form.right_click_menu_selected_colors[0])
16157
- if toplevel_form.right_click_menu_selected_colors[1] not in (COLOR_SYSTEM_DEFAULT, None):
16158
- top_menu.config(activebackground=toplevel_form.right_click_menu_selected_colors[1])
16276
+ top_menu.config(bg=color_check(toplevel_form.right_click_menu_background_color))
16277
+ top_menu.config(fg=color_check(toplevel_form.right_click_menu_text_color))
16278
+ top_menu.config(disabledforeground=color_check_blank(toplevel_form.right_click_menu_disabled_text_color))
16279
+ top_menu.config(font=toplevel_form.right_click_menu_font)
16280
+
16281
+ top_menu.config(activeforeground=color_check(toplevel_form.right_click_menu_selected_colors[0]))
16282
+ top_menu.config(activebackground=color_check(toplevel_form.right_click_menu_selected_colors[1]))
16159
16283
  AddMenuItem(top_menu, menu[1], element, right_click_menu=True)
16160
16284
  element.TKRightClickMenu = top_menu
16161
16285
  element.RightClickMenu = menu # Store the menu in the element in case the window was the source
@@ -16316,12 +16440,6 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
16316
16440
  elif element.Justification.lower().startswith('r'):
16317
16441
  row_justify = 'r'
16318
16442
 
16319
- # anchor=tk.NW
16320
- # side = tk.LEFT
16321
- # row_justify = element.Justification
16322
-
16323
- # element.Widget = element.TKColFrame
16324
-
16325
16443
  expand = True
16326
16444
  if element.expand_x and element.expand_y:
16327
16445
  fill = tk.BOTH
@@ -16369,6 +16487,8 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
16369
16487
  borderwidth=bd,
16370
16488
  bd=bd,
16371
16489
  )
16490
+ element.PanedWindow.configure(sashwidth=element.SashWidth, sashcursor=element.SashCursor)
16491
+
16372
16492
  if element.Relief is not None:
16373
16493
  element.PanedWindow.configure(relief=element.Relief)
16374
16494
  element.PanedWindow.configure(handlesize=element.HandleSize)
@@ -16857,7 +16977,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
16857
16977
  element.TKEntry.configure(background=element.BackgroundColor, selectforeground=element.BackgroundColor)
16858
16978
 
16859
16979
  if text_color not in (None, COLOR_SYSTEM_DEFAULT):
16860
- _widget_set_fg_color(element.TKEntry, text_color) # trying out the refactored color function... many places to change still
16980
+ element.TKEntry.config(fg=text_color) # trying out the refactored color function... many places to change still
16861
16981
  element.TKEntry.configure(selectbackground=text_color)
16862
16982
  element.TKEntry.config(insertbackground=text_color)
16863
16983
  if element.selected_background_color not in (None, COLOR_SYSTEM_DEFAULT):
@@ -17202,7 +17322,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
17202
17322
  element.reroute_stderr_to_here()
17203
17323
 
17204
17324
  # row_should_expand = True
17205
- # ------------------------- CHECKBOX pleacement element ------------------------- #
17325
+ # ------------------------- CHECKBOX placement element ------------------------- #
17206
17326
  elif element_type == ELEM_TYPE_INPUT_CHECKBOX:
17207
17327
  element = element # type: Checkbox
17208
17328
  width = 0 if auto_size_text else element_size[0]
@@ -18079,7 +18199,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
18079
18199
  # element.TKTreeview.pack_forget()
18080
18200
  treeview.bind("<<TreeviewSelect>>", element._treeview_selected)
18081
18201
  if element.Tooltip is not None: # tooltip
18082
- element.TooltipObject = Tooltip(element.TKTreeview, text=element.Tooltip, timeout=toplevel_form.tooltip_time, offset=toplevel_form.tooltip_offset, background_color=toplevel_form.tooltip_background_color, text_color=toplevel_form.tooltip_text_color, font=toplevel_form.tooltip_font)
18202
+ element.TooltipObject = ToolTip(element.TKTreeview, text=element.Tooltip, timeout=toplevel_form.tooltip_time, offset=toplevel_form.tooltip_offset, background_color=toplevel_form.tooltip_background_color, text_color=toplevel_form.tooltip_text_color, font=toplevel_form.tooltip_font)
18083
18203
  _add_right_click_menu_and_grab(element)
18084
18204
 
18085
18205
  if tclversion_detailed == '8.6.9' and ENABLE_TREEVIEW_869_PATCH:
@@ -18308,14 +18428,18 @@ def StartupTK(window):
18308
18428
 
18309
18429
  # If location is None, then there's no need to hide the window. Let it build where it is going to end up being.
18310
18430
  if DEFAULT_HIDE_WINDOW_WHEN_CREATING is True and window.Location is not None:
18311
- try:
18312
- if not running_mac() or \
18313
- (running_mac() and not window.NoTitleBar) or \
18314
- (running_mac() and window.NoTitleBar and not _mac_should_apply_notitlebar_patch()):
18315
-
18316
- root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
18317
- except Exception as e:
18318
- print('*** Exception setting alpha channel to zero while creating window ***', e)
18431
+ if not window.NoTitleBar or window._has_custom_titlebar:
18432
+ # print(f'[{fname()}] Hiding window using withdraw')
18433
+ root.withdraw()
18434
+ else:
18435
+ # print(f'[{fname()}] Hiding window using alpha')
18436
+ try:
18437
+ if not running_mac() or \
18438
+ (running_mac() and not window.NoTitleBar) or \
18439
+ (running_mac() and window.NoTitleBar and not _mac_should_apply_notitlebar_patch()):
18440
+ root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
18441
+ except Exception as e:
18442
+ print('*** Exception setting alpha channel to zero while creating window ***', e)
18319
18443
 
18320
18444
  if window.BackgroundColor is not None and window.BackgroundColor != COLOR_SYSTEM_DEFAULT:
18321
18445
  root.configure(background=window.BackgroundColor)
@@ -18332,11 +18456,28 @@ def StartupTK(window):
18332
18456
  if not running_mac():
18333
18457
  _no_titlebar_setup(window)
18334
18458
 
18335
- if not window.Resizable:
18459
+ if isinstance(window.Resizable, tuple):
18460
+ root.resizable(window.Resizable[0], window.Resizable[1])
18461
+ elif not window.Resizable:
18336
18462
  root.resizable(False, False)
18337
18463
 
18464
+ # Can't use the old way because it crashes on Linux, likely always has
18465
+ # if window.DisableMinimize:
18466
+ # root.attributes("-toolwindow", 1)
18467
+
18338
18468
  if window.DisableMinimize:
18339
- root.attributes("-toolwindow", 1)
18469
+ if running_windows():
18470
+ root.attributes('-toolwindow', 1)
18471
+ elif running_linux():
18472
+ try:
18473
+ root.attributes('-type', 'dialog') # X11 hint - most window managers remove the minimize button for dialog-type windows
18474
+ except Exception:
18475
+ pass
18476
+ elif running_mac() and not window.NoTitleBar: # Skip Mac if no titlebar. Otherwise, list all the buttons to include, skipping collapseBox
18477
+ try:
18478
+ root.tk.call('::tk::unsupported::MacWindowStyle', 'style', root._w, 'document', 'closeBox resizable horizontalZoom verticalZoom fullZoom')
18479
+ except Exception:
18480
+ pass
18340
18481
 
18341
18482
  if window.KeepOnTop:
18342
18483
  root.wm_attributes("-topmost", 1)
@@ -18368,12 +18509,29 @@ def StartupTK(window):
18368
18509
  root.bind("<Control-Down>", window._move_callback)
18369
18510
 
18370
18511
  window.set_icon(window.WindowIcon)
18371
- try:
18372
- alpha_channel = 1 if window.AlphaChannel is None else window.AlphaChannel
18373
- root.attributes('-alpha', alpha_channel) # Make window visible again
18374
- except Exception as e:
18375
- print('**** Error setting Alpha Channel to {} after window was created ****'.format(alpha_channel), e)
18376
- # pass
18512
+ alpha_channel = 1 if window.AlphaChannel is None else window.AlphaChannel
18513
+ if window.NoTitleBar and not window._has_custom_titlebar:
18514
+ # print(f'[{fname()}] Uhiding window using alpha')
18515
+ try:
18516
+ alpha_channel = 1 if window.AlphaChannel is None else window.AlphaChannel
18517
+ root.attributes('-alpha', alpha_channel) # Make window visible again
18518
+ except Exception as e:
18519
+ print('**** Error setting Alpha Channel to {} after window was created ****'.format(alpha_channel), e)
18520
+ else:
18521
+ try:
18522
+ if root.state() == 'withdrawn':
18523
+ if alpha_channel != 1 or window._has_custom_titlebar:
18524
+ root.attributes('-alpha', alpha_channel) # wrapper already exists here, so this sticks on X11
18525
+ # print(f'[{fname()}] Uhiding window using deiconify')
18526
+ root.deiconify() # first and only map
18527
+ else:
18528
+ # print(f'[{fname()}] Uhiding window using alpha')
18529
+ root.attributes('-alpha', alpha_channel) # Make window visible again
18530
+ except Exception as e:
18531
+ print('**** Error making window visible after it was created ****', e)
18532
+
18533
+
18534
+
18377
18535
 
18378
18536
  if window.ReturnKeyboardEvents and not window.NonBlocking:
18379
18537
  root.bind("<KeyRelease>", window._KeyboardCallback)
@@ -19239,22 +19397,7 @@ def set_global_icon(icon):
19239
19397
  # ============================== set_options ========#
19240
19398
  # Sets the icon to be used by default #
19241
19399
  # ===================================================#
19242
- def set_options(icon=None, button_color=None, element_size=(None, None), button_element_size=(None, None),
19243
- margins=(None, None),
19244
- element_padding=(None, None), auto_size_text=None, auto_size_buttons=None, font=None, border_width=None,
19245
- slider_border_width=None, slider_relief=None, slider_orientation=None,
19246
- autoclose_time=None, message_box_line_width=None,
19247
- progress_meter_border_depth=None, progress_meter_style=None,
19248
- progress_meter_relief=None, progress_meter_color=None, progress_meter_size=None,
19249
- text_justification=None, background_color=None, element_background_color=None,
19250
- text_element_background_color=None, input_elements_background_color=None, input_text_color=None,
19251
- scrollbar_color=None, text_color=None, element_text_color=None, debug_win_size=(None, None),
19252
- window_location=(None, None), error_button_color=(None, None), tooltip_time=None, tooltip_font=None, use_ttk_buttons=None, ttk_theme=None,
19253
- suppress_error_popups=None, suppress_raise_key_errors=None, suppress_key_guessing=None,warn_button_key_duplicates=False, enable_treeview_869_patch=None,
19254
- enable_mac_notitlebar_patch=None, use_custom_titlebar=None, titlebar_background_color=None, titlebar_text_color=None, titlebar_font=None,
19255
- titlebar_icon=None, user_settings_path=None, pysimplegui_settings_path=None, pysimplegui_settings_filename=None, keep_on_top=None, dpi_awareness=None, scaling=None, disable_modal_windows=None, force_modal_windows=None, tooltip_offset=(None, None),
19256
- sbar_trough_color=None, sbar_background_color=None, sbar_arrow_color=None, sbar_width=None, sbar_arrow_width=None, sbar_frame_color=None, sbar_relief=None, alpha_channel=None,
19257
- hide_window_when_creating=None, use_button_shortcuts=None, watermark_text=None, win_app_id=None):
19400
+ def set_options(icon=None, button_color=None, element_size=(None, None), button_element_size=(None, None), margins=(None, None), element_padding=(None, None), auto_size_text=None, auto_size_buttons=None, font=None, border_width=None, slider_border_width=None, slider_relief=None, slider_orientation=None, autoclose_time=None, message_box_line_width=None, progress_meter_border_depth=None, progress_meter_style=None, progress_meter_relief=None, progress_meter_color=None, progress_meter_size=None, text_justification=None, background_color=None, element_background_color=None, text_element_background_color=None, input_elements_background_color=None, input_text_color=None, scrollbar_color=None, text_color=None, element_text_color=None, debug_win_size=(None, None), window_location=(None, None), error_button_color=(None, None), tooltip_time=None, tooltip_font=None, tooltip_offset=(None, None), tooltip_background_color=None, tooltip_text_color=None, set_tooltip_to_element_key=None, use_ttk_buttons=None, ttk_theme=None, suppress_error_popups=None, suppress_raise_key_errors=None, suppress_key_guessing=None,warn_button_key_duplicates=False, enable_treeview_869_patch=None, enable_mac_notitlebar_patch=None, use_custom_titlebar=None, titlebar_background_color=None, titlebar_text_color=None, titlebar_font=None, titlebar_icon=None, user_settings_path=None, pysimplegui_settings_path=None, pysimplegui_settings_filename=None, keep_on_top=None, dpi_awareness=None, scaling=None, disable_modal_windows=None, force_modal_windows=None, sbar_trough_color=None, sbar_background_color=None, sbar_arrow_color=None, sbar_width=None, sbar_arrow_width=None, sbar_frame_color=None, sbar_relief=None, alpha_channel=None, hide_window_when_creating=None, use_button_shortcuts=None, watermark_text=None, win_app_id=None, **kwargs):
19258
19401
  """
19259
19402
  :param icon: Can be either a filename or Base64 value. For Windows if filename, it MUST be ICO format. For Linux, must NOT be ICO. Most portable is to use a Base64 of a PNG file. This works universally across all OS's
19260
19403
  :type icon: bytes | str
@@ -19324,6 +19467,14 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19324
19467
  :type tooltip_time: (int)
19325
19468
  :param tooltip_font: font to use for all tooltips
19326
19469
  :type tooltip_font: str or Tuple[str, int] or Tuple[str, int, str]
19470
+ :param tooltip_offset: Offset to use for tooltips as a tuple. These values will be added to the mouse location when the widget was entered.
19471
+ :type tooltip_offset: ((None, None) | (int, int))
19472
+ :param tooltip_text_color: Text color to use as the default for tooltips
19473
+ :type tooltip_text_color: str
19474
+ :param tooltip_background_color: Text background color to use as the default for tooltips
19475
+ :type tooltip_background_color: str
19476
+ :param set_tooltip_to_element_key: If True then all elements' tooltips will be set to the element's key. Useful for debugging
19477
+ :type set_tooltip_to_element_key: bool
19327
19478
  :param use_ttk_buttons: if True will cause all buttons to be ttk buttons
19328
19479
  :type use_ttk_buttons: (bool)
19329
19480
  :param ttk_theme: Theme to use with ttk widgets. Choices (on Windows) include - 'default', 'winnative', 'clam', 'alt', 'classic', 'vista', 'xpnative'
@@ -19366,8 +19517,6 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19366
19517
  :type disable_modal_windows: (bool)
19367
19518
  :param force_modal_windows: If True then all windows will be modal (the disable option will be ignored... all windows will be forced to be modal)
19368
19519
  :type force_modal_windows: (bool)
19369
- :param tooltip_offset: Offset to use for tooltips as a tuple. These values will be added to the mouse location when the widget was entered.
19370
- :type tooltip_offset: ((None, None) | (int, int))
19371
19520
  :param sbar_trough_color: Scrollbar color of the trough
19372
19521
  :type sbar_trough_color: (str)
19373
19522
  :param sbar_background_color: Scrollbar color of the background of the arrow buttons at the ends AND the color of the "thumb" (the thing you grab and slide). Switches to arrow color when mouse is over
@@ -19392,8 +19541,8 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19392
19541
  :type watermark_text: (str)
19393
19542
  :param win_app_id: For Windows only. Sets string that's passed to Windows to control combining icons on taskbar. Default is " mycompany.myproduct.subproduct.version". Windows with same ID combine on taskbar. Change before creating a window to set that window's ID.
19394
19543
  :type win_app_id: (str)
19395
- :return: None
19396
- :rtype: None
19544
+ :param **kwargs: The keyword args
19545
+ :type **kwargs: (Any)
19397
19546
  """
19398
19547
 
19399
19548
  global DEFAULT_ELEMENT_SIZE
@@ -19426,11 +19575,14 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19426
19575
  global DEFAULT_WINDOW_LOCATION
19427
19576
  global DEFAULT_ELEMENT_TEXT_COLOR
19428
19577
  global DEFAULT_INPUT_TEXT_COLOR
19578
+ global TOOLTIP_FONT
19579
+ global DEFAULT_TOOLTIP_OFFSET
19429
19580
  global DEFAULT_TOOLTIP_TIME
19581
+ global TOOLTIP_BACKGROUND_COLOR
19582
+ global TOOLTIP_TEXT_COLOR
19430
19583
  global DEFAULT_ERROR_BUTTON_COLOR
19431
19584
  global DEFAULT_TTK_THEME
19432
19585
  global USE_TTK_BUTTONS
19433
- global TOOLTIP_FONT
19434
19586
  global SUPPRESS_ERROR_POPUPS
19435
19587
  global SUPPRESS_RAISE_KEY_ERRORS
19436
19588
  global SUPPRESS_KEY_GUESSING
@@ -19449,7 +19601,6 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19449
19601
  global DEFAULT_SCALING
19450
19602
  global DEFAULT_MODAL_WINDOWS_ENABLED
19451
19603
  global DEFAULT_MODAL_WINDOWS_FORCED
19452
- global DEFAULT_TOOLTIP_OFFSET
19453
19604
  global DEFAULT_ALPHA_CHANNEL
19454
19605
  global _pysimplegui_user_settings
19455
19606
  global ttk_part_overrides_from_options
@@ -19558,6 +19709,18 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19558
19709
  if tooltip_time is not None:
19559
19710
  DEFAULT_TOOLTIP_TIME = tooltip_time
19560
19711
 
19712
+ if tooltip_font is not None:
19713
+ TOOLTIP_FONT = tooltip_font
19714
+
19715
+ if tooltip_background_color is not None:
19716
+ TOOLTIP_BACKGROUND_COLOR = tooltip_background_color
19717
+
19718
+ if tooltip_text_color is not None:
19719
+ TOOLTIP_TEXT_COLOR = tooltip_text_color
19720
+
19721
+ if tooltip_offset != (None, None):
19722
+ DEFAULT_TOOLTIP_OFFSET = tooltip_offset
19723
+
19561
19724
  if error_button_color != (None, None):
19562
19725
  DEFAULT_ERROR_BUTTON_COLOR = error_button_color
19563
19726
 
@@ -19567,8 +19730,6 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19567
19730
  if use_ttk_buttons is not None:
19568
19731
  USE_TTK_BUTTONS = use_ttk_buttons
19569
19732
 
19570
- if tooltip_font is not None:
19571
- TOOLTIP_FONT = tooltip_font
19572
19733
 
19573
19734
  if suppress_error_popups is not None:
19574
19735
  SUPPRESS_ERROR_POPUPS = suppress_error_popups
@@ -19635,10 +19796,6 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19635
19796
  if force_modal_windows is not None:
19636
19797
  DEFAULT_MODAL_WINDOWS_FORCED = force_modal_windows
19637
19798
 
19638
- if tooltip_offset != (None, None):
19639
- DEFAULT_TOOLTIP_OFFSET = tooltip_offset
19640
-
19641
-
19642
19799
  if alpha_channel is not None:
19643
19800
  DEFAULT_ALPHA_CHANNEL = alpha_channel
19644
19801
 
@@ -19673,6 +19830,9 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19673
19830
  if watermark_text is not None:
19674
19831
  Window._watermark_user_text = watermark_text
19675
19832
 
19833
+ if set_tooltip_to_element_key is not None:
19834
+ Window._set_tooltip_to_element_key = set_tooltip_to_element_key
19835
+
19676
19836
 
19677
19837
  if win_app_id is not None:
19678
19838
  # Enables the correct application icon to be shown on the Windows taskbar
@@ -19682,8 +19842,8 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
19682
19842
  except Exception as e:
19683
19843
  print('Error setting App ID', e)
19684
19844
 
19685
- return True
19686
-
19845
+ if len(kwargs) != 0:
19846
+ print('set_options - bad parameter set.', 'The parameter(s) used in set_options were not recognized options:\n', *[f' {key}={value}\n' for key, value in kwargs.items()])
19687
19847
  # ----------------------------------------------------------------- #
19688
19848
 
19689
19849
  # .########.##.....##.########.##.....##.########..######.
@@ -22576,18 +22736,12 @@ def popup_menu(window, element, menu_def, title=None, location=(None, None)):
22576
22736
 
22577
22737
  element._popup_menu_location = location
22578
22738
  top_menu = tk.Menu(window.TKroot, tearoff=True, tearoffcommand=element._tearoff_menu_callback)
22579
- if window.right_click_menu_background_color not in (COLOR_SYSTEM_DEFAULT, None):
22580
- top_menu.config(bg=window.right_click_menu_background_color)
22581
- if window.right_click_menu_text_color not in (COLOR_SYSTEM_DEFAULT, None):
22582
- top_menu.config(fg=window.right_click_menu_text_color)
22583
- if window.right_click_menu_disabled_text_color not in (COLOR_SYSTEM_DEFAULT, None):
22584
- top_menu.config(disabledforeground=window.right_click_menu_disabled_text_color)
22585
- if window.right_click_menu_font is not None:
22586
- top_menu.config(font=window.right_click_menu_font)
22587
- if window.right_click_menu_selected_colors[0] != COLOR_SYSTEM_DEFAULT:
22588
- top_menu.config(activeforeground=window.right_click_menu_selected_colors[0])
22589
- if window.right_click_menu_selected_colors[1] != COLOR_SYSTEM_DEFAULT:
22590
- top_menu.config(activebackground=window.right_click_menu_selected_colors[1])
22739
+ top_menu.config(bg=color_check(window.right_click_menu_background_color))
22740
+ top_menu.config(fg=color_check(window.right_click_menu_text_color))
22741
+ top_menu.config(disabledforeground=color_check_blank(window.right_click_menu_disabled_text_color))
22742
+ top_menu.config(font=window.right_click_menu_font)
22743
+ top_menu.config(activeforeground=color_check(window.right_click_menu_selected_colors[0]))
22744
+ top_menu.config(activebackground=color_check(window.right_click_menu_selected_colors[1]))
22591
22745
  top_menu.config(title=window.Title if title is None else title)
22592
22746
  AddMenuItem(top_menu, menu_def[1], element, right_click_menu=True)
22593
22747
  # element.Widget.bind('<Button-3>', element._RightClickMenuCallback)
@@ -22633,7 +22787,7 @@ def _error_popup_with_traceback(title, *args, emoji=None):
22633
22787
  error_message = line
22634
22788
  break
22635
22789
  if file_info_pysimplegui is None:
22636
- _error_popup_with_code(title, None, None, 'Did not find your traceback info', *args, emoji=emoji)
22790
+ _error_popup_with_code(title, None, None, 'Did not find your traceback info', *args, trace_details=trace_details, emoji=emoji)
22637
22791
  _PopupErrorGlobals.showing_error = False
22638
22792
  return
22639
22793
 
@@ -22649,24 +22803,26 @@ def _error_popup_with_traceback(title, *args, emoji=None):
22649
22803
  return
22650
22804
  filename = error_parts[0][error_parts[0].index('File ') + 5:]
22651
22805
  line_num = error_parts[1][error_parts[1].index('line ') + 5:]
22652
- _error_popup_with_code(title, filename, line_num, error_message, *args, emoji=emoji)
22806
+ _error_popup_with_code(title, filename, line_num, error_message, *args, trace_details=trace_details, emoji=emoji)
22653
22807
  _PopupErrorGlobals.showing_error = False
22654
22808
 
22655
22809
 
22656
- def _error_popup_with_code(title, filename, line_num, *args, emoji=None):
22810
+ def _error_popup_with_code(title, filename, line_num, *args, trace_details=None, emoji=None):
22657
22811
  """
22658
22812
  Makes the error popup window
22659
22813
 
22660
- :param title: The title that will be shown in the popup's titlebar and in the first line of the window
22661
- :type title: str
22662
- :param filename: The filename to show.. may not be the filename that actually encountered the exception!
22663
- :type filename: str
22664
- :param line_num: Line number within file with the error
22665
- :type line_num: int | str
22666
- :param args: A variable number of lines of messages
22667
- :type args: *Any
22668
- :param emoji: An optional BASE64 Encoded image to shows in the error window. If set to '' (empty string) then no emoji will be shown
22669
- :type emoji: bytes | str
22814
+ :param title: The title that will be shown in the popup's titlebar and in the first line of the window
22815
+ :type title: str
22816
+ :param filename: The filename to show.. may not be the filename that actually encountered the exception!
22817
+ :type filename: str
22818
+ :param line_num: Line number within file with the error
22819
+ :type line_num: int | str
22820
+ :param args: A variable number of lines of messages
22821
+ :type args: *Any
22822
+ :param trace_details: A variable number of lines of messages
22823
+ :type trace_details: List[str]
22824
+ :param emoji: An optional BASE64 Encoded image to shows in the error window. If set to '' (empty string) then no emoji will be shown
22825
+ :type emoji: bytes | str
22670
22826
  """
22671
22827
  editor_filename = execute_get_editor()
22672
22828
  if emoji is None:
@@ -22689,8 +22845,13 @@ def _error_popup_with_code(title, filename, line_num, *args, emoji=None):
22689
22845
  for line in lines:
22690
22846
  max_line_len = max(max_line_len, max([len(s) for s in line]))
22691
22847
 
22848
+ multiline_contents = '\n'.join(['\n'.join(line) for line in lines])
22849
+ if trace_details is not None:
22850
+ multiline_contents += '\n'.join(trace_details)
22851
+
22692
22852
  layout += [[Text(''.join(line), size=(min(max_line_len, 90), None))] for line in lines]
22693
- layout += [[Button('Close'), Button('Take me to error', disabled=True if not editor_filename else False), Button('Kill Application', button_color='white on red')]]
22853
+ layout += [[Multiline(multiline_contents, size=(100,20))]]
22854
+ layout += [[Button('Close and keep running', k='Close'), Button('Take me to error', disabled=True if not editor_filename else False), Button('Kill Application', button_color='white on red')]]
22694
22855
  if not editor_filename:
22695
22856
  layout += [[Text('Configure editor in the Global settings to enable "Take me to error" feature')]]
22696
22857
  window = Window(title, layout, keep_on_top=True)
@@ -25978,7 +26139,7 @@ def _create_main_window():
25978
26139
 
25979
26140
  tab_elem_layout = [[Push(), Text('These sample controls show what\'s possible with PySimpleGUI'), Push()],
25980
26141
  [TabGroup([[tab_elem_graph, tab_elem_basic, tab_elem_table_tree, tab_elem_mline_sliders, tab_elem_popups]], key='-TAB_GROUP-', expand_x=True, expand_y=True)]]
25981
-
26142
+
25982
26143
  tab_elem = Tab('Elements\n', tab_elem_layout, key='-TAB ELEMENTS-', expand_x=True, expand_y=True)
25983
26144
 
25984
26145
  # ------------------------- Settings Tab -------------------------
@@ -25987,7 +26148,7 @@ def _create_main_window():
25987
26148
  [B('Global\nSettings', size=(8,2), k='-GLOBAL SETTINGS-', tooltip='Settings across all PySimpleGUI programs'),]]
25988
26149
 
25989
26150
  tab_settings = Tab('Settings\n', tab_settings_layout, key='-TAB SETTINGS-', expand_x=True, expand_y=True)
25990
-
26151
+
25991
26152
 
25992
26153
 
25993
26154
  # ------------------------- VERSIONS Tab -------------------------
@@ -26288,7 +26449,7 @@ def main_global_pysimplegui_settings():
26288
26449
  settings = pysimplegui_user_settings.read()
26289
26450
 
26290
26451
  editor_format_dict = {
26291
- 'pycharm': '<editor> --line <line> <file>',
26452
+ 'pycharm': '<editor> <file> --line <line>',
26292
26453
  'notepad++': '<editor> -n<line> <file>',
26293
26454
  'sublime': '<editor> <file>:<line>',
26294
26455
  'vim': '<editor> +<line> <file>',
@@ -26301,7 +26462,7 @@ def main_global_pysimplegui_settings():
26301
26462
  'idle': '<editor> <file>'}
26302
26463
 
26303
26464
  tooltip = 'Format strings for some popular editors/IDEs:\n' + \
26304
- 'PyCharm - <editor> --line <line> <file>\n' + \
26465
+ 'PyCharm - <editor> <file> --line <line> \n' + \
26305
26466
  'Notepad++ - <editor> -n<line> <file>\n' + \
26306
26467
  'Sublime - <editor> <file>:<line>\n' + \
26307
26468
  'vim - <editor> +<line> <file>\n' + \
@@ -26568,8 +26729,16 @@ def _convert_window_to_tk(window):
26568
26729
  location_anchor = WIN_ANCHOR_CENTER
26569
26730
 
26570
26731
  master.update_idletasks() # don't forget to do updates or values are bad
26571
- win_width = master.winfo_width()
26572
- win_height = master.winfo_height()
26732
+ if master.state() == 'withdrawn': # withdrawn (never mapped) windows report winfo_width/height as 1
26733
+ # print(f'[{fname()}] Getting size of withdrawn window')
26734
+ win_width = window._Size[0] if window._Size[0] is not None else master.winfo_reqwidth()
26735
+ win_height = window._Size[1] if window._Size[1] is not None else master.winfo_reqheight()
26736
+ else:
26737
+ # print(f'[{fname()}] Getting size of normal window')
26738
+ win_width = master.winfo_width()
26739
+ win_height = master.winfo_height()
26740
+ # win_width = master.winfo_width()
26741
+ # win_height = master.winfo_height()
26573
26742
 
26574
26743
  xoff = yoff = 0
26575
26744
  if location_anchor == WIN_ANCHOR_CENTER:
@@ -26676,7 +26845,10 @@ if tclversion_detailed.startswith('8.5'):
26676
26845
  # Enables the correct application icon to be shown on the Windows taskbar
26677
26846
  if running_windows():
26678
26847
  try:
26679
- myappid = 'mycompany.myproduct.subproduct.version' # Add an app ID on Windows to control Windows taskbar icon combining
26848
+ # Derived from the main script's path so each PySimpleGUI program is its own app on the taskbar (same script twice still combines).
26849
+ # The old hardcoded 'mycompany.myproduct.subproduct.version' made ALL PySimpleGUI apps one app, so icons bled between programs.
26850
+ _appid_main_file = getattr(sys.modules.get('__main__'), '__file__', '') or 'interactive'
26851
+ myappid = 'PySimpleGUI.App.' + hashlib.md5(os.path.abspath(_appid_main_file).encode('utf-8')).hexdigest() # Add an app ID on Windows to control Windows taskbar icon combining
26680
26852
  ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
26681
26853
  except Exception as e:
26682
26854
  print('Error setting App ID', e)