Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "selectforeground" and "selectbackground" attributes to CTkComиobox, CTkEntry and CTkTextbox #2341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions customtkinter/windows/widgets/ctk_combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion customtkinter/windows/widgets/ctk_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion customtkinter/windows/widgets/ctk_textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down