diff --git a/customtkinter/windows/widgets/ctk_combobox.py b/customtkinter/windows/widgets/ctk_combobox.py index 99495641..09579a44 100644 --- a/customtkinter/windows/widgets/ctk_combobox.py +++ b/customtkinter/windows/widgets/ctk_combobox.py @@ -43,6 +43,8 @@ def __init__(self, variable: Union[tkinter.Variable, None] = None, command: Union[Callable[[str], Any], None] = None, justify: str = "left", + selectbackground: Optional[Union[str, Tuple[str, str]]] = None, + selectforeground: Optional[Union[str, Tuple[str, str]]] = None, **kwargs): # transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass @@ -59,7 +61,9 @@ def __init__(self, self._button_hover_color = ThemeManager.theme["CTkComboBox"]["button_hover_color"] if button_hover_color is None else self._check_color_type(button_hover_color) self._text_color = ThemeManager.theme["CTkComboBox"]["text_color"] if text_color is None else self._check_color_type(text_color) self._text_color_disabled = ThemeManager.theme["CTkComboBox"]["text_color_disabled"] if text_color_disabled is None else self._check_color_type(text_color_disabled) - + self._selectbackground = None if selectbackground is None else self._check_color_type(selectbackground) #if parameter missing use default selection color, maybe replace with ThemeManager.theme["CTkComboBox"]["button_color"] or ThemeManager.theme["CTkButton"]["button_color"] + self._selectforeground = ThemeManager.theme["CTkComboBox"]["text_color"] if selectforeground is None else self._check_color_type(selectforeground) + # font self._font = CTkFont() if font is None else self._check_font_type(font) if isinstance(self._font, CTkFont): @@ -205,7 +209,9 @@ def _draw(self, no_color_updates=False): disabledbackground=self._apply_appearance_mode(self._fg_color), disabledforeground=self._apply_appearance_mode(self._text_color_disabled), highlightcolor=self._apply_appearance_mode(self._fg_color), - insertbackground=self._apply_appearance_mode(self._text_color)) + insertbackground=self._apply_appearance_mode(self._text_color), + selectbackground=self._apply_appearance_mode(self._selectbackground), + selectforeground=self._apply_appearance_mode(self._selectforeground)) if self._state == tkinter.DISABLED: self._canvas.itemconfig("dropdown_arrow", @@ -295,6 +301,13 @@ def configure(self, require_redraw=False, **kwargs): if "justify" in kwargs: self._entry.configure(justify=kwargs.pop("justify")) + if "selectbackground" in kwargs: + self._selectbackground = self._check_color_type(kwargs.pop("selectbackground")) + require_redraw = True + if "selectforeground" in kwargs: + self._selectforeground = self._check_color_type(kwargs.pop("selectforeground")) + require_redraw = True + super().configure(require_redraw=require_redraw, **kwargs) def cget(self, attribute_name: str) -> any: @@ -321,6 +334,10 @@ def cget(self, attribute_name: str) -> any: return self._text_color elif attribute_name == "text_color_disabled": return self._text_color_disabled + elif attribute_name == "selectbackground": + return self._selectbackground + elif attribute_name == "selectforeground": + return self._selectforeground elif attribute_name == "font": return self._font diff --git a/customtkinter/windows/widgets/ctk_entry.py b/customtkinter/windows/widgets/ctk_entry.py index cdc0220b..863e69e3 100644 --- a/customtkinter/windows/widgets/ctk_entry.py +++ b/customtkinter/windows/widgets/ctk_entry.py @@ -20,7 +20,7 @@ class CTkEntry(CTkBaseClass): # attributes that are passed to and managed by the tkinter entry only: _valid_tk_entry_attributes = {"exportselection", "insertborderwidth", "insertofftime", "insertontime", "insertwidth", "justify", "selectborderwidth", - "show", "takefocus", "validate", "validatecommand", "xscrollcommand"} + "show", "takefocus", "validate", "validatecommand", "xscrollcommand", "selectforeground", "selectbackground"} def __init__(self, master: Any, diff --git a/customtkinter/windows/widgets/ctk_textbox.py b/customtkinter/windows/widgets/ctk_textbox.py index 4b3a165f..700184ed 100644 --- a/customtkinter/windows/widgets/ctk_textbox.py +++ b/customtkinter/windows/widgets/ctk_textbox.py @@ -29,7 +29,7 @@ class CTkTextbox(CTkBaseClass): "insertborderwidth", "insertofftime", "insertontime", "insertwidth", "maxundo", "padx", "pady", "selectborderwidth", "spacing1", "spacing2", "spacing3", "state", "tabs", "takefocus", "undo", "wrap", - "xscrollcommand", "yscrollcommand"} + "xscrollcommand", "yscrollcommand", "selectforeground", "selectbackground"} def __init__(self, master: any,