You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After exploring, I found that the current implementation does not support the use of images for button values in CTkSegmentedButton .
My current workaround is creating a customized version of CTkSegmentedButton with extended functionality to accommodate images for buttons, through:
Extension of the init() method to accept an additional parameter for images.
Extension of the _create_button() method to facilitate the creation of buttons with images.
class customizedSegmentedButton(customtkinter.CTkSegmentedButton):
def __init__(self, master, *args, images=None, **kwargs):
self._images = images # we modify how we want first before any __init__ calls of the based class!
super().__init__(master, *args, **kwargs)
def _create_button(self, index: int, value: str) -> customtkinter.CTkButton:
image = self._images[index] if self._images else None
new_button = customtkinter.CTkButton(self,
width=0,
height=self._current_height,
corner_radius=self._sb_corner_radius,
border_width=self._sb_border_width,
fg_color=self._sb_unselected_color,
border_color=self._sb_fg_color,
hover_color=self._sb_unselected_hover_color,
text_color=self._sb_text_color,
text_color_disabled=self._sb_text_color_disabled,
text=value,
font=self._font,
state=self._state,
command=lambda v=value: self.set(v, from_button_callback=True),
image=image,
background_corner_colors=None,
round_width_to_even_numbers=False,
round_height_to_even_numbers=False) # DrawEngine rendering option (so that theres no gap between buttons)
return new_button
As a temporary fix, it still has problems as it is incompatible incase you wanted to use empty values for the buttons!
Please see if you can upgrade customtkinter to support this natively!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
After exploring, I found that the current implementation does not support the use of images for button values in CTkSegmentedButton .
My current workaround is creating a customized version of CTkSegmentedButton with extended functionality to accommodate images for buttons, through:
As a temporary fix, it still has problems as it is incompatible incase you wanted to use empty values for the buttons!
Please see if you can upgrade customtkinter to support this natively!
Beta Was this translation helpful? Give feedback.
All reactions