From d103fc42f199949670655d2eb5383d1e09d35bdb Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Sun, 2 Oct 2022 03:53:27 +0200 Subject: [PATCH] added cget method to base class and button #395 --- customtkinter/widgets/ctk_button.py | 32 ++++++++++++++++++++++ customtkinter/widgets/widget_base_class.py | 10 +++++++ 2 files changed, 42 insertions(+) diff --git a/customtkinter/widgets/ctk_button.py b/customtkinter/widgets/ctk_button.py index 5190aaa..b114993 100644 --- a/customtkinter/widgets/ctk_button.py +++ b/customtkinter/widgets/ctk_button.py @@ -300,6 +300,38 @@ class CTkButton(CTkBaseClass): super().configure(require_redraw=require_redraw, **kwargs) + def cget(self, key: str) -> any: + if key == "fg_color": + return self._fg_color + elif key == "hover_color": + return self._hover_color + elif key == "border_color": + return self._border_color + elif key == "text_color": + return self._text_color + elif key == "text_color_disabled": + return self._text_color_disabled + elif key == "text": + return self._text + elif key == "textvariable": + return self._textvariable + elif key == "text_font": + return self._text_font + elif key == "command": + return self._command + elif key == "hover": + return self._hover + elif key == "border_width": + return self._border_width + elif key == "image": + return self._image + elif key == "compound": + return self._compound + elif key == "state": + return self._state + else: + return super().cget(key) + def _set_cursor(self): if Settings.cursor_manipulation_enabled: if self._state == tkinter.DISABLED: diff --git a/customtkinter/widgets/widget_base_class.py b/customtkinter/widgets/widget_base_class.py index 4d48d11..77af625 100644 --- a/customtkinter/widgets/widget_base_class.py +++ b/customtkinter/widgets/widget_base_class.py @@ -133,6 +133,16 @@ class CTkBaseClass(tkinter.Frame): if require_redraw: self._draw() + def cget(self, key: str): + if key == "bg_color": + return self._bg_color + elif key == "width": + return self._desired_width + elif key == "height": + return self._desired_height + else: + return super().cget(key) + def _update_dimensions_event(self, event): # only redraw if dimensions changed (for performance), independent of scaling if round(self._current_width) != round(event.width / self._widget_scaling) or round(self._current_height) != round(event.height / self._widget_scaling):