This commit is contained in:
demberto
2023-04-18 18:50:20 +05:30
parent a9b44c180e
commit 79cd10ddfd
13 changed files with 53 additions and 33 deletions

View File

@ -51,7 +51,6 @@ class CTkInputDialog(CTkToplevel):
self.grab_set() # make other windows not clickable self.grab_set() # make other windows not clickable
def _create_widgets(self): def _create_widgets(self):
self.grid_columnconfigure((0, 1), weight=1) self.grid_columnconfigure((0, 1), weight=1)
self.rowconfigure(0, weight=1) self.rowconfigure(0, weight=1)

View File

@ -197,7 +197,7 @@ class CTk(tkinter.Tk, CTkAppearanceModeBaseClass, CTkScalingBaseClass):
super().geometry(self._apply_geometry_scaling(geometry_string)) super().geometry(self._apply_geometry_scaling(geometry_string))
# update width and height attributes # update width and height attributes
width, height, x, y = self._parse_geometry_string(geometry_string) width, height, *_ = self._parse_geometry_string(geometry_string)
if width is not None and height is not None: if width is not None and height is not None:
self._current_width = max(self._min_width, min(width, self._max_width)) # bound value between min and max self._current_width = max(self._min_width, min(width, self._max_width)) # bound value between min and max
self._current_height = max(self._min_height, min(height, self._max_height)) self._current_height = max(self._min_height, min(height, self._max_height))

View File

@ -56,11 +56,11 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
self._current_width = 200 # initial window size, always without scaling self._current_width = 200 # initial window size, always without scaling
self._current_height = 200 self._current_height = 200
self._min_width: int = 0 self._min_width: int | None = 0
self._min_height: int = 0 self._min_height: int | None = 0
self._max_width: int = 1_000_000 self._max_width: int | None = 1_000_000
self._max_height: int = 1_000_000 self._max_height: int | None = 1_000_000
self._last_resizable_args: tuple[list, dict] | None = None # (args, kwargs) self._last_resizable_args: tuple[list[int], dict[str, float]] | None = None # (args, kwargs)
self._fg_color = ThemeManager.theme["CTkToplevel"]["fg_color"] if fg_color is None else self._check_color_type(fg_color) self._fg_color = ThemeManager.theme["CTkToplevel"]["fg_color"] if fg_color is None else self._check_color_type(fg_color)

View File

@ -4,6 +4,11 @@ import sys
import tkinter import tkinter
from typing import Any, Callable from typing import Any, Callable
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
from .core_rendering import CTkCanvas, DrawEngine from .core_rendering import CTkCanvas, DrawEngine
from .core_widget_classes import CTkBaseClass from .core_widget_classes import CTkBaseClass
from .font import CTkFont from .font import CTkFont
@ -36,7 +41,7 @@ class CTkCheckBox(CTkBaseClass):
text: str = "CTkCheckBox", text: str = "CTkCheckBox",
font: tuple[Any, ...] | CTkFont | None = None, font: tuple[Any, ...] | CTkFont | None = None,
textvariable: tkinter.Variable | None = None, textvariable: tkinter.Variable | None = None,
state: str = tkinter.NORMAL, state: Literal["normal", "disabled", "readonly"] = "normal",
hover: bool = True, hover: bool = True,
command: Callable[[], None] | None = None, command: Callable[[], None] | None = None,
onvalue: int | str = 1, onvalue: int | str = 1,

View File

@ -43,11 +43,11 @@ class CTkComboBox(CTkBaseClass):
font: tuple[Any, ...] | CTkFont | None = None, font: tuple[Any, ...] | CTkFont | None = None,
dropdown_font: tuple[Any, ...] | CTkFont | None = None, dropdown_font: tuple[Any, ...] | CTkFont | None = None,
values: list[str] | None = None, values: list[str] | None = None,
state: str = tkinter.NORMAL, state: Literal["normal", "disabled", "readonly"] = "normal",
hover: bool = True, hover: bool = True,
variable: tkinter.Variable | None = None, variable: tkinter.Variable | None = None,
command: Callable[[str], None] | None = None, command: Callable[[str], None] | None = None,
justify: str = "left", justify: Literal["left", "center", "right"] = "left",
**kwargs: Any): **kwargs: Any):
# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
@ -401,13 +401,13 @@ class CTkComboBox(CTkBaseClass):
if self._state is not tkinter.DISABLED and len(self._values) > 0: if self._state is not tkinter.DISABLED and len(self._values) > 0:
self._open_dropdown_menu() self._open_dropdown_menu()
def bind(self, sequence=None, command=None, add: Literal["+", True] = True): def bind(self, sequence: str | None = None, command=None, add: Literal["+"] | bool = True):
""" called on the tkinter.Entry """ """ called on the tkinter.Entry """
if not (add == "+" or add is True): if not (add == "+" or add is True):
raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks")
self._entry.bind(sequence, command, add=True) self._entry.bind(sequence, command, add=True)
def unbind(self, sequence=None, funcid=None): def unbind(self, sequence=None, funcid: str | None = None):
""" called on the tkinter.Entry """ """ called on the tkinter.Entry """
if funcid is not None: if funcid is not None:
raise ValueError("'funcid' argument can only be None, because there is a bug in" + raise ValueError("'funcid' argument can only be None, because there is a bug in" +

View File

@ -45,7 +45,7 @@ class CTkEntry(CTkBaseClass):
textvariable: tkinter.Variable | None = None, textvariable: tkinter.Variable | None = None,
placeholder_text: str | None = None, placeholder_text: str | None = None,
font: tuple[Any, ...] | CTkFont | None = None, font: tuple[Any, ...] | CTkFont | None = None,
state: str = tkinter.NORMAL, state: Literal["normal", "disabled", "readonly"] = "normal",
**kwargs: Any): **kwargs: Any):
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
@ -288,7 +288,7 @@ class CTkEntry(CTkBaseClass):
else: else:
return super().cget(attribute_name) # cget of CTkBaseClass return super().cget(attribute_name) # cget of CTkBaseClass
def bind(self, sequence=None, command=None, add: Literal["+", True] = True): def bind(self, sequence=None, command=None, add: Literal["+"] | bool = True):
""" called on the tkinter.Entry """ """ called on the tkinter.Entry """
if not (add == "+" or add is True): if not (add == "+" or add is True):
raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks")

View File

@ -1,7 +1,8 @@
from __future__ import annotations from __future__ import annotations
import sys import sys
from typing import Any import tkinter
from typing import Any, Callable
if sys.version_info >= (3, 8): if sys.version_info >= (3, 8):
from typing import Literal from typing import Literal
@ -189,13 +190,13 @@ class CTkFrame(CTkBaseClass):
else: else:
return super().cget(attribute_name) return super().cget(attribute_name)
def bind(self, sequence=None, command=None, add: Literal["+", True] = True): def bind(self, sequence: str | None = None, command: Callable[[tkinter.Event[Any]], None] | None = None, add: Literal["+"] | bool = True):
""" called on the tkinter.Canvas """ """ called on the tkinter.Canvas """
if not (add == "+" or add is True): if not (add == "+" or add is True):
raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks")
self._canvas.bind(sequence, command, add=True) self._canvas.bind(sequence, command, add=True)
def unbind(self, sequence=None, funcid=None): def unbind(self, sequence=None, funcid: str | None = None):
""" called on the tkinter.Canvas """ """ called on the tkinter.Canvas """
if funcid is not None: if funcid is not None:
raise ValueError("'funcid' argument can only be None, because there is a bug in" + raise ValueError("'funcid' argument can only be None, because there is a bug in" +

View File

@ -5,6 +5,11 @@ import sys
import tkinter import tkinter
from typing import Any, Callable from typing import Any, Callable
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
from .core_rendering import CTkCanvas, DrawEngine from .core_rendering import CTkCanvas, DrawEngine
from .core_widget_classes import CTkBaseClass, DropdownMenu from .core_widget_classes import CTkBaseClass, DropdownMenu
from .font import CTkFont from .font import CTkFont
@ -37,7 +42,7 @@ class CTkOptionMenu(CTkBaseClass):
dropdown_font: tuple[Any, ...] | CTkFont | None = None, dropdown_font: tuple[Any, ...] | CTkFont | None = None,
values: list | None = None, values: list | None = None,
variable: tkinter.Variable | None = None, variable: tkinter.Variable | None = None,
state: str = tkinter.NORMAL, state: Literal["normal", "disabled", "readonly"] = "normal",
hover: bool = True, hover: bool = True,
command: Callable[[str], None] | None = None, command: Callable[[str], None] | None = None,
dynamic_resizing: bool = True, dynamic_resizing: bool = True,

View File

@ -4,6 +4,11 @@ import sys
import tkinter import tkinter
from typing import Any, Callable from typing import Any, Callable
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
from .core_rendering import CTkCanvas, DrawEngine from .core_rendering import CTkCanvas, DrawEngine
from .core_widget_classes import CTkBaseClass from .core_widget_classes import CTkBaseClass
from .font import CTkFont from .font import CTkFont
@ -38,7 +43,7 @@ class CTkRadioButton(CTkBaseClass):
textvariable: tkinter.Variable | None = None, textvariable: tkinter.Variable | None = None,
variable: tkinter.Variable | None = None, variable: tkinter.Variable | None = None,
value: int | str = 0, value: int | str = 0,
state: str = tkinter.NORMAL, state: Literal["normal", "disabled", "readonly"] = "normal",
hover: bool = True, hover: bool = True,
command: Callable[..., None] | None = None, command: Callable[..., None] | None = None,
**kwargs: Any): **kwargs: Any):

View File

@ -264,7 +264,7 @@ class CTkScrollbar(CTkBaseClass):
def get(self): def get(self):
return self._start_value, self._end_value return self._start_value, self._end_value
def bind(self, sequence=None, command: Callable[..., None] | None = None, add: Literal["+", True] = True): def bind(self, sequence=None, command: Callable[..., None] | None = None, add: Literal["+"] | bool = True):
""" called on the tkinter.Canvas """ """ called on the tkinter.Canvas """
if not (add == "+" or add is True): if not (add == "+" or add is True):
raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks")

View File

@ -337,7 +337,7 @@ class CTkSlider(CTkBaseClass):
fill=self._apply_appearance_mode(self._button_color), fill=self._apply_appearance_mode(self._button_color),
outline=self._apply_appearance_mode(self._button_color)) outline=self._apply_appearance_mode(self._button_color))
def _round_to_step_size(self, value) -> float: def _round_to_step_size(self, value: float) -> float:
if self._number_of_steps is not None: if self._number_of_steps is not None:
step_size = (self._to - self._from_) / self._number_of_steps step_size = (self._to - self._from_) / self._number_of_steps
value = self._to - (round((self._to - value) / step_size) * step_size) value = self._to - (round((self._to - value) / step_size) * step_size)
@ -348,7 +348,7 @@ class CTkSlider(CTkBaseClass):
def get(self) -> float: def get(self) -> float:
return self._output_value return self._output_value
def set(self, output_value, from_variable_callback: bool = False): def set(self, output_value: float, from_variable_callback: bool = False):
if self._from_ < self._to: if self._from_ < self._to:
if output_value > self._to: if output_value > self._to:
output_value = self._to output_value = self._to

View File

@ -4,6 +4,11 @@ import sys
import tkinter import tkinter
from typing import Any, Callable from typing import Any, Callable
if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
from .core_rendering import CTkCanvas, DrawEngine from .core_rendering import CTkCanvas, DrawEngine
from .core_widget_classes import CTkBaseClass from .core_widget_classes import CTkBaseClass
from .font import CTkFont from .font import CTkFont
@ -43,7 +48,7 @@ class CTkSwitch(CTkBaseClass):
variable: tkinter.Variable | None = None, variable: tkinter.Variable | None = None,
hover: bool = True, hover: bool = True,
command: Callable[..., None] | None = None, command: Callable[..., None] | None = None,
state: str = tkinter.NORMAL, state: Literal["normal", "disabled", "readonly"] = "normal",
**kwargs: Any): **kwargs: Any):
# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass # transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass

View File

@ -129,7 +129,7 @@ class CTkTextbox(CTkBaseClass):
self.after(50, self._check_if_scrollbars_needed, None, True) self.after(50, self._check_if_scrollbars_needed, None, True)
self._draw() self._draw()
def _create_grid_for_text_and_scrollbars(self, re_grid_textbox=False, re_grid_x_scrollbar=False, re_grid_y_scrollbar=False): def _create_grid_for_text_and_scrollbars(self, re_grid_textbox: bool = False, re_grid_x_scrollbar: bool = False, re_grid_y_scrollbar: bool = False):
# configure 2x2 grid # configure 2x2 grid
self.grid_rowconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1)
@ -158,7 +158,7 @@ class CTkTextbox(CTkBaseClass):
else: else:
self._y_scrollbar.grid_forget() self._y_scrollbar.grid_forget()
def _check_if_scrollbars_needed(self, event=None, continue_loop: bool = False): def _check_if_scrollbars_needed(self, event: tkinter.Event[Any] | None = None, continue_loop: bool = False):
""" Method hides or places the scrollbars if they are needed on key release event of tkinter.text widget """ """ Method hides or places the scrollbars if they are needed on key release event of tkinter.text widget """
if self._scrollbars_activated: if self._scrollbars_activated:
@ -355,7 +355,7 @@ class CTkTextbox(CTkBaseClass):
def focus_force(self): def focus_force(self):
return self._textbox.focus_force() return self._textbox.focus_force()
def insert(self, index: int, text, tags=None): def insert(self, index: int, text: str, tags=None):
return self._textbox.insert(index, text, tags) return self._textbox.insert(index, text, tags)
def get(self, index1, index2=None): def get(self, index1, index2=None):
@ -435,16 +435,16 @@ class CTkTextbox(CTkBaseClass):
def see(self, index): def see(self, index):
return self._textbox.see(index) return self._textbox.see(index)
def tag_add(self, tagName, index1, index2=None): def tag_add(self, tagName: str, index1, index2=None):
return self._textbox.tag_add(tagName, index1, index2) return self._textbox.tag_add(tagName, index1, index2)
def tag_bind(self, tagName, sequence, func, add=None): def tag_bind(self, tagName: str, sequence: str, func, add: bool | Literal["", "+"] | None = None):
return self._textbox.tag_bind(tagName, sequence, func, add) return self._textbox.tag_bind(tagName, sequence, func, add)
def tag_cget(self, tagName, option): def tag_cget(self, tagName: str, option: str):
return self._textbox.tag_cget(tagName, option) return self._textbox.tag_cget(tagName, option)
def tag_config(self, tagName, **kwargs: Any): def tag_config(self, tagName: str, **kwargs: Any):
if "font" in kwargs: if "font" in kwargs:
raise AttributeError("'font' option forbidden, because would be incompatible with scaling") raise AttributeError("'font' option forbidden, because would be incompatible with scaling")
return self._textbox.tag_config(tagName, **kwargs) return self._textbox.tag_config(tagName, **kwargs)
@ -476,10 +476,10 @@ class CTkTextbox(CTkBaseClass):
def tag_unbind(self, tagName: str, sequence, funcid=None): def tag_unbind(self, tagName: str, sequence, funcid=None):
return self._textbox.tag_unbind(tagName, sequence, funcid) return self._textbox.tag_unbind(tagName, sequence, funcid)
def window_cget(self, index: int, option): def window_cget(self, index: int, option: str):
raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)") raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)")
def window_configure(self, index: int, option): def window_configure(self, index: int, option: str):
raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)") raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)")
def window_create(self, index: int, **kwargs: Any): def window_create(self, index: int, **kwargs: Any):
@ -500,7 +500,7 @@ class CTkTextbox(CTkBaseClass):
def yview(self, *args): def yview(self, *args):
return self._textbox.yview(*args) return self._textbox.yview(*args)
def yview_moveto(self, fraction): def yview_moveto(self, fraction: float):
return self._textbox.yview_moveto(fraction) return self._textbox.yview_moveto(fraction)
def yview_scroll(self, n, what): def yview_scroll(self, n, what):