diff --git a/customtkinter/windows/ctk_toplevel.py b/customtkinter/windows/ctk_toplevel.py index 3a351dc6..a24ae574 100644 --- a/customtkinter/windows/ctk_toplevel.py +++ b/customtkinter/windows/ctk_toplevel.py @@ -38,14 +38,6 @@ def __init__(self, *args, CTkScalingBaseClass.__init__(self, scaling_type="window") check_kwargs_empty(kwargs, raise_error=True) - try: - # Set Windows titlebar icon - if sys.platform.startswith("win"): - customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - self.after(200, lambda: self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))) - except Exception: - pass - self._current_width = 200 # initial window size, always without scaling self._current_height = 200 self._min_width: int = 0 diff --git a/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py b/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py index 610f46a5..009b5dc9 100644 --- a/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py +++ b/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py @@ -2,7 +2,7 @@ import warnings import tkinter import tkinter.ttk as ttk -from typing import Union, Callable, Tuple +from typing import Union, Callable, Tuple, Optional try: from typing import TypedDict @@ -35,10 +35,12 @@ def __init__(self, height: int = 0, bg_color: Union[str, Tuple[str, str]] = "transparent", + + name: Optional[str] = None, **kwargs): # call init methods of super classes - tkinter.Frame.__init__(self, master=master, width=width, height=height, **pop_from_dict_by_set(kwargs, self._valid_tk_frame_attributes)) + tkinter.Frame.__init__(self, master=master, width=width, height=height, name=name, **pop_from_dict_by_set(kwargs, self._valid_tk_frame_attributes)) CTkAppearanceModeBaseClass.__init__(self) CTkScalingBaseClass.__init__(self, scaling_type="widget") diff --git a/customtkinter/windows/widgets/ctk_button.py b/customtkinter/windows/widgets/ctk_button.py index d79a944b..9ba95149 100644 --- a/customtkinter/windows/widgets/ctk_button.py +++ b/customtkinter/windows/widgets/ctk_button.py @@ -46,10 +46,12 @@ def __init__(self, command: Union[Callable[[], None], None] = None, compound: str = "left", anchor: str = "center", + + name: Optional[str] = None, **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) + super().__init__(master=master, bg_color=bg_color, width=width, height=height, name=name, **kwargs) # shape self._corner_radius: int = ThemeManager.theme["CTkButton"]["corner_radius"] if corner_radius is None else corner_radius diff --git a/customtkinter/windows/widgets/ctk_entry.py b/customtkinter/windows/widgets/ctk_entry.py index db543868..543ef870 100644 --- a/customtkinter/windows/widgets/ctk_entry.py +++ b/customtkinter/windows/widgets/ctk_entry.py @@ -39,10 +39,12 @@ def __init__(self, placeholder_text: Union[str, None] = None, font: Optional[Union[tuple, CTkFont]] = None, state: str = tkinter.NORMAL, + + name: Optional[str] = None, **kwargs): # transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass - super().__init__(master=master, bg_color=bg_color, width=width, height=height) + super().__init__(master=master, bg_color=bg_color, width=width, height=height, name=name) # configure grid system (1x1) self.grid_rowconfigure(0, weight=1) diff --git a/customtkinter/windows/widgets/ctk_frame.py b/customtkinter/windows/widgets/ctk_frame.py index 67bf1615..a9ae37d0 100644 --- a/customtkinter/windows/widgets/ctk_frame.py +++ b/customtkinter/windows/widgets/ctk_frame.py @@ -27,10 +27,12 @@ def __init__(self, background_corner_colors: Union[Tuple[Union[str, Tuple[str, str]]], None] = None, overwrite_preferred_drawing_method: Union[str, None] = None, + + name: Optional[str] = None, **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) + super().__init__(master=master, bg_color=bg_color, width=width, height=height, name=name, **kwargs) # color self._border_color = ThemeManager.theme["CTkFrame"]["border_color"] if border_color is None else self._check_color_type(border_color) diff --git a/customtkinter/windows/widgets/ctk_label.py b/customtkinter/windows/widgets/ctk_label.py index 0eb78317..f3abc1e9 100644 --- a/customtkinter/windows/widgets/ctk_label.py +++ b/customtkinter/windows/widgets/ctk_label.py @@ -20,7 +20,7 @@ class CTkLabel(CTkBaseClass): # attributes that are passed to and managed by the tkinter entry only: _valid_tk_label_attributes = {"cursor", "justify", "padx", "pady", - "textvariable", "state", "takefocus", "underline"} + "textvariable", "state", "takefocus", "underline", "name"} def __init__(self, master: any, @@ -39,10 +39,12 @@ def __init__(self, compound: str = "center", anchor: str = "center", # label anchor: center, n, e, s, w wraplength: int = 0, + + name: Optional[str] = None, **kwargs): # transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass - super().__init__(master=master, bg_color=bg_color, width=width, height=height) + super().__init__(master=master, bg_color=bg_color, width=width, height=height, name=name) # color self._fg_color = ThemeManager.theme["CTkLabel"]["fg_color"] if fg_color is None else self._check_color_type(fg_color, transparency=True) diff --git a/customtkinter/windows/widgets/ctk_scrollable_frame.py b/customtkinter/windows/widgets/ctk_scrollable_frame.py index 687f4adf..1e05745c 100644 --- a/customtkinter/windows/widgets/ctk_scrollable_frame.py +++ b/customtkinter/windows/widgets/ctk_scrollable_frame.py @@ -36,7 +36,8 @@ 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", + name: Optional[str] = None): self._orientation = orientation @@ -45,7 +46,8 @@ def __init__(self, self._desired_height = height self._parent_frame = CTkFrame(master=master, width=0, height=0, corner_radius=corner_radius, - border_width=border_width, bg_color=bg_color, fg_color=fg_color, border_color=border_color) + border_width=border_width, bg_color=bg_color, fg_color=fg_color, + border_color=border_color, name=name) self._parent_canvas = tkinter.Canvas(master=self._parent_frame, highlightthickness=0) self._set_scroll_increments() @@ -314,3 +316,20 @@ def lift(self, aboveThis=None): def lower(self, belowThis=None): self._parent_frame.lower(belowThis) + + def scroll_to_y(self, y_pos: int): + """ + scrolls the view to a specific y position. + + parameters: + y_pos (int): The y position to scroll to, in pixels. + """ + # get the total scrollable area height + # the 4th element of the bbox tuple is the height + scrollable_height = self._parent_canvas.bbox("all")[3] + + # calculate the fraction of the total scrollable area + fraction = y_pos / scrollable_height + + # use yview_moveto to scroll to the specific y position + self._parent_canvas.yview_moveto(fraction)