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

better dropdown image, alias added to each widget #2518

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
Binary file not shown.
Binary file added customtkinter/assets/fonts/test4.otf
Binary file not shown.
2 changes: 1 addition & 1 deletion customtkinter/windows/ctk_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .widgets.scaling import CTkScalingBaseClass
from .widgets.appearance_mode import CTkAppearanceModeBaseClass

from customtkinter.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty
from customtkinter_FV_Automation.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty

CTK_PARENT_CLASS = tkinter.Tk

Expand Down
2 changes: 1 addition & 1 deletion customtkinter/windows/ctk_toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .widgets.scaling import CTkScalingBaseClass
from .widgets.appearance_mode import CTkAppearanceModeBaseClass

from customtkinter.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty
from customtkinter_FV_Automation.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty


class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseClass):
Expand Down
1 change: 0 additions & 1 deletion customtkinter/windows/widgets/core_rendering/ctk_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def create_aa_circle(self, x_pos: int, y_pos: int, radius: int, angle: int = 0,
return circle_1

def coords(self, tag_or_id, *args):

if type(tag_or_id) == str and "ctk_aa_circle_font_element" in self.gettags(tag_or_id):
coords_id = self.find_withtag(tag_or_id)[0] # take the lowest id for the given tag
super().coords(coords_id, *args[:2])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,6 @@ def draw_dropdown_arrow(self, x_position: Union[int, float], y_position: Union[i
self._canvas.create_text(0, 0, text="Y", font=("CustomTkinter_shapes_font", -size), tags="dropdown_arrow", anchor=tkinter.CENTER)
self._canvas.tag_raise("dropdown_arrow")
requires_recoloring = True

self._canvas.itemconfigure("dropdown_arrow", font=("CustomTkinter_shapes_font", -size))
self._canvas.coords("dropdown_arrow", x_position, y_position)

Expand Down
12 changes: 11 additions & 1 deletion customtkinter/windows/widgets/ctk_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ def __init__(self,
command: Union[Callable[[], Any], None] = None,
compound: str = "left",
anchor: str = "center",
alias: str = "NA",
**kwargs):

# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)

self.alias = alias

# shape
self._corner_radius: int = ThemeManager.theme["CTkButton"]["corner_radius"] if corner_radius is None else corner_radius
self._corner_radius = min(self._corner_radius, round(self._current_height / 2))
Expand Down Expand Up @@ -184,6 +187,7 @@ def _draw(self, no_color_updates=False):
super()._draw(no_color_updates)

if self._background_corner_colors is not None:

self._draw_engine.draw_background_corners(self._apply_widget_scaling(self._current_width),
self._apply_widget_scaling(self._current_height))
self._canvas.itemconfig("background_corner_top_left", fill=self._apply_appearance_mode(self._background_corner_colors[0]))
Expand All @@ -192,7 +196,7 @@ def _draw(self, no_color_updates=False):
self._canvas.itemconfig("background_corner_bottom_left", fill=self._apply_appearance_mode(self._background_corner_colors[3]))
else:
self._canvas.delete("background_parts")

requires_recoloring = self._draw_engine.draw_rounded_rect_with_border(self._apply_widget_scaling(self._current_width),
self._apply_widget_scaling(self._current_height),
self._apply_widget_scaling(self._corner_radius),
Expand Down Expand Up @@ -439,6 +443,9 @@ def configure(self, require_redraw=False, **kwargs):
self._create_grid()
require_redraw = True

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

super().configure(require_redraw=require_redraw, **kwargs)

def cget(self, attribute_name: str) -> any:
Expand Down Expand Up @@ -480,6 +487,9 @@ def cget(self, attribute_name: str) -> any:
return self._compound
elif attribute_name == "anchor":
return self._anchor
elif attribute_name == "alias":
return self.alias

else:
return super().cget(attribute_name)

Expand Down
8 changes: 8 additions & 0 deletions customtkinter/windows/widgets/ctk_checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ def __init__(self,
onvalue: Union[int, str] = 1,
offvalue: Union[int, str] = 0,
variable: Union[tkinter.Variable, None] = None,
alias: str = "NA",
**kwargs):

# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)

self.alias = alias

# dimensions
self._checkbox_width = checkbox_width
self._checkbox_height = checkbox_height
Expand Down Expand Up @@ -291,6 +294,9 @@ def configure(self, require_redraw=False, **kwargs):
self._textvariable = kwargs.pop("textvariable")
self._text_label.configure(textvariable=self._textvariable)

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

if "variable" in kwargs:
if self._variable is not None and self._variable != "":
self._variable.trace_remove("write", self._variable_callback_name) # remove old variable callback
Expand Down Expand Up @@ -343,6 +349,8 @@ def cget(self, attribute_name: str) -> any:
return self._offvalue
elif attribute_name == "variable":
return self._variable
elif attribute_name == "alias":
return self.alias
else:
return super().cget(attribute_name)

Expand Down
9 changes: 9 additions & 0 deletions customtkinter/windows/widgets/ctk_combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ def __init__(self,
variable: Union[tkinter.Variable, None] = None,
command: Union[Callable[[str], Any], None] = None,
justify: str = "left",
alias: str = "NA",
**kwargs):

# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)

self.alias = alias

# shape
self._corner_radius = ThemeManager.theme["CTkComboBox"]["corner_radius"] if corner_radius is None else corner_radius
self._border_width = ThemeManager.theme["CTkComboBox"]["border_width"] if border_width is None else border_width
Expand Down Expand Up @@ -295,6 +298,10 @@ def configure(self, require_redraw=False, **kwargs):
if "justify" in kwargs:
self._entry.configure(justify=kwargs.pop("justify"))

if "alias" in kwargs:
self.alias = kwargs.pop("alias")


super().configure(require_redraw=require_redraw, **kwargs)

def cget(self, attribute_name: str) -> any:
Expand Down Expand Up @@ -338,6 +345,8 @@ def cget(self, attribute_name: str) -> any:
return self._command
elif attribute_name == "justify":
return self._entry.cget("justify")
elif attribute_name == "alias":
return self.alias
else:
return super().cget(attribute_name)

Expand Down
8 changes: 8 additions & 0 deletions customtkinter/windows/widgets/ctk_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ def __init__(self,
placeholder_text: Union[str, None] = None,
font: Optional[Union[tuple, CTkFont]] = None,
state: str = tkinter.NORMAL,
alias: str = "NA",
**kwargs):

# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height)

self.alias = alias

# configure grid system (1x1)
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
Expand Down Expand Up @@ -249,6 +252,9 @@ def configure(self, require_redraw=False, **kwargs):
else:
self._entry.configure(show=kwargs.pop("show"))

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

self._entry.configure(**pop_from_dict_by_set(kwargs, self._valid_tk_entry_attributes)) # configure Tkinter.Entry
super().configure(require_redraw=require_redraw, **kwargs) # configure CTkBaseClass

Expand All @@ -275,6 +281,8 @@ def cget(self, attribute_name: str) -> any:
return self._font
elif attribute_name == "state":
return self._state
elif attribute_name == "alias":
return self.alias

elif attribute_name in self._valid_tk_entry_attributes:
return self._entry.cget(attribute_name) # cget of tkinter.Entry
Expand Down
8 changes: 8 additions & 0 deletions customtkinter/windows/widgets/ctk_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ def __init__(self,

background_corner_colors: Union[Tuple[Union[str, Tuple[str, str]]], None] = None,
overwrite_preferred_drawing_method: Union[str, None] = None,
alias: str = "NA",
**kwargs):

# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)

self.alias = alias

# color
self._border_color = ThemeManager.theme["CTkFrame"]["border_color"] if border_color is None else self._check_color_type(border_color)

Expand Down Expand Up @@ -163,6 +166,9 @@ def configure(self, require_redraw=False, **kwargs):
if "border_width" in kwargs:
self._border_width = kwargs.pop("border_width")
require_redraw = True

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

super().configure(require_redraw=require_redraw, **kwargs)

Expand All @@ -178,6 +184,8 @@ def cget(self, attribute_name: str) -> any:
return self._border_color
elif attribute_name == "background_corner_colors":
return self._background_corner_colors
elif attribute_name == "alias":
return self.alias

else:
return super().cget(attribute_name)
Expand Down
8 changes: 8 additions & 0 deletions customtkinter/windows/widgets/ctk_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ def __init__(self,
compound: str = "center",
anchor: str = "center", # label anchor: center, n, e, s, w
wraplength: int = 0,
alias: str = "NA",
**kwargs):

# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height)

self.alias = alias

# color
self._fg_color = ThemeManager.theme["CTkLabel"]["fg_color"] if fg_color is None else self._check_color_type(fg_color, transparency=True)
self._text_color = ThemeManager.theme["CTkLabel"]["text_color"] if text_color is None else self._check_color_type(text_color)
Expand Down Expand Up @@ -234,6 +237,9 @@ def configure(self, require_redraw=False, **kwargs):
self._wraplength = kwargs.pop("wraplength")
self._label.configure(wraplength=self._apply_widget_scaling(self._wraplength))

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

self._label.configure(**pop_from_dict_by_set(kwargs, self._valid_tk_label_attributes)) # configure tkinter.Label
super().configure(require_redraw=require_redraw, **kwargs) # configure CTkBaseClass

Expand All @@ -260,6 +266,8 @@ def cget(self, attribute_name: str) -> any:
return self._anchor
elif attribute_name == "wraplength":
return self._wraplength
elif attribute_name == "alias":
return self.alias

elif attribute_name in self._valid_tk_label_attributes:
return self._label.cget(attribute_name) # cget of tkinter.Label
Expand Down
10 changes: 9 additions & 1 deletion customtkinter/windows/widgets/ctk_optionmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ def __init__(self,
command: Union[Callable[[str], Any], None] = None,
dynamic_resizing: bool = True,
anchor: str = "w",
alias: str = "NA",
**kwargs):

# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)

self.alias = alias

# color variables
self._fg_color = ThemeManager.theme["CTkOptionMenu"]["fg_color"] if fg_color is None else self._check_color_type(fg_color)
self._button_color = ThemeManager.theme["CTkOptionMenu"]["button_color"] if button_color is None else self._check_color_type(button_color)
Expand Down Expand Up @@ -305,6 +308,9 @@ def configure(self, require_redraw=False, **kwargs):
if "anchor" in kwargs:
self._text_label.configure(anchor=kwargs.pop("anchor"))

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

super().configure(require_redraw=require_redraw, **kwargs)

def cget(self, attribute_name: str) -> any:
Expand Down Expand Up @@ -346,7 +352,9 @@ def cget(self, attribute_name: str) -> any:
return self._dynamic_resizing
elif attribute_name == "anchor":
return self._text_label.cget("anchor")

elif attribute_name == "alias":
return self.alias

else:
return super().cget(attribute_name)

Expand Down
8 changes: 8 additions & 0 deletions customtkinter/windows/widgets/ctk_progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self,
mode: Literal["determinate", "indeterminate"] = "determinate",
determinate_speed: float = 1,
indeterminate_speed: float = 1,
alias: str = "NA",
**kwargs):

# set default dimensions according to orientation
Expand All @@ -53,6 +54,8 @@ def __init__(self,
# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)

self.alias = alias

# color
self._border_color = ThemeManager.theme["CTkProgressBar"]["border_color"] if border_color is None else self._check_color_type(border_color)
self._fg_color = ThemeManager.theme["CTkProgressBar"]["fg_color"] if fg_color is None else self._check_color_type(fg_color)
Expand Down Expand Up @@ -200,6 +203,9 @@ def configure(self, require_redraw=False, **kwargs):
if "indeterminate_speed" in kwargs:
self._indeterminate_speed = kwargs.pop("indeterminate_speed")

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

super().configure(require_redraw=require_redraw, **kwargs)

def cget(self, attribute_name: str) -> any:
Expand All @@ -225,6 +231,8 @@ def cget(self, attribute_name: str) -> any:
return self._determinate_speed
elif attribute_name == "indeterminate_speed":
return self._indeterminate_speed
elif attribute_name == "alias":
return self.alias

else:
return super().cget(attribute_name)
Expand Down
8 changes: 8 additions & 0 deletions customtkinter/windows/widgets/ctk_radiobutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ def __init__(self,
state: str = tkinter.NORMAL,
hover: bool = True,
command: Union[Callable, Any] = None,
alias: str = "NA",
**kwargs):

# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
super().__init__(master=master, bg_color=bg_color, width=width, height=height, **kwargs)

self.alias = alias

# dimensions
self._radiobutton_width = radiobutton_width
self._radiobutton_height = radiobutton_height
Expand Down Expand Up @@ -276,6 +279,9 @@ def configure(self, require_redraw=False, **kwargs):
self._textvariable = kwargs.pop("textvariable")
self._text_label.configure(textvariable=self._textvariable)

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

if "variable" in kwargs:
if self._variable is not None:
self._variable.trace_remove("write", self._variable_callback_name)
Expand Down Expand Up @@ -328,6 +334,8 @@ def cget(self, attribute_name: str) -> any:
return self._hover
elif attribute_name == "command":
return self._command
elif attribute_name == "alias":
return self.alias

else:
return super().cget(attribute_name)
Expand Down
10 changes: 9 additions & 1 deletion customtkinter/windows/widgets/ctk_scrollable_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ def __init__(self,
label_text: str = "",
label_font: Optional[Union[tuple, CTkFont]] = None,
label_anchor: str = "center",
orientation: Literal["vertical", "horizontal"] = "vertical"):
orientation: Literal["vertical", "horizontal"] = "vertical",
alias: str = "NA"):

self._orientation = orientation

self.alias = alias

# dimensions independent of scaling
self._desired_width = width # _desired_width and _desired_height, represent desired size set by width and height
self._desired_height = height
Expand Down Expand Up @@ -203,6 +206,9 @@ def configure(self, **kwargs):
if "label_anchor" in kwargs:
self._label.configure(anchor=kwargs.pop("label_anchor"))

if "alias" in kwargs:
self.alias = kwargs.pop("alias")

self._parent_frame.configure(**kwargs)

def cget(self, attribute_name: str):
Expand All @@ -228,6 +234,8 @@ def cget(self, attribute_name: str):
return self._scrollbar.cget("button_color")
elif attribute_name.startswith("scrollbar_button_hover_color"):
return self._scrollbar.cget("button_hover_color")
elif attribute_name == "alias":
return self.alias

else:
return self._parent_frame.cget(attribute_name)
Expand Down
Loading