Skip to content

Commit

Permalink
added border_width, corner_radius to configure of CTkSegmentedButton,…
Browse files Browse the repository at this point in the history
… removed border_color because has no effect TomSchimansky#1562
  • Loading branch information
TomSchimansky committed May 8, 2023
1 parent c6b16ce commit 6d2f31c
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions customtkinter/windows/widgets/ctk_segmented_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .font import CTkFont
from .ctk_button import CTkButton
from .ctk_frame import CTkFrame
from .utility import check_kwargs_empty


class CTkSegmentedButton(CTkFrame):
Expand Down Expand Up @@ -40,10 +41,9 @@ def __init__(self,
variable: Union[tkinter.Variable, None] = None,
dynamic_resizing: bool = True,
command: Union[Callable[[str], None], None] = None,
state: str = "normal",
**kwargs):
state: str = "normal"):

super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)
super().__init__(master=master, bg_color=bg_color, width=width, height=height)

self._sb_fg_color = ThemeManager.theme["CTkSegmentedButton"]["fg_color"] if fg_color is None else self._check_color_type(fg_color)

Expand Down Expand Up @@ -197,6 +197,23 @@ def _create_buttons_from_values(self):
self._configure_button_corners_for_index(index)

def configure(self, **kwargs):
if "width" in kwargs:
super().configure(width=kwargs.pop("width"))

if "height" in kwargs:
super().configure(height=kwargs.pop("height"))

if "corner_radius" in kwargs:
self._sb_corner_radius = kwargs.pop("corner_radius")
super().configure(corner_radius=self._sb_corner_radius)
for button in self._buttons_dict.values():
button.configure(corner_radius=self._sb_corner_radius)

if "border_width" in kwargs:
self._sb_border_width = kwargs.pop("border_width")
for button in self._buttons_dict.values():
button.configure(border_width=self._sb_border_width)

if "bg_color" in kwargs:
super().configure(bg_color=kwargs.pop("bg_color"))

Expand Down Expand Up @@ -296,14 +313,20 @@ def configure(self, **kwargs):
for button in self._buttons_dict.values():
button.configure(state=self._state)

super().configure(**kwargs)
check_kwargs_empty(kwargs, raise_error=True)

def cget(self, attribute_name: str) -> any:
if attribute_name == "corner_radius":
if attribute_name == "width":
return super().cget(attribute_name)
elif attribute_name == "height":
return super().cget(attribute_name)
elif attribute_name == "corner_radius":
return self._sb_corner_radius
elif attribute_name == "border_width":
return self._sb_border_width

elif attribute_name == "bg_color":
return super().cget(attribute_name)
elif attribute_name == "fg_color":
return self._sb_fg_color
elif attribute_name == "selected_color":
Expand Down Expand Up @@ -331,7 +354,7 @@ def cget(self, attribute_name: str) -> any:
return self._command

else:
return super().cget(attribute_name)
raise ValueError(f"'{attribute_name}' is not a supported argument. Look at the documentation for supported arguments.")

def set(self, value: str, from_variable_callback: bool = False, from_button_callback: bool = False):
if value == self._current_value:
Expand Down

0 comments on commit 6d2f31c

Please sign in to comment.