added cget method to base class and button #395

This commit is contained in:
Tom Schimansky 2022-10-02 03:53:27 +02:00
parent d6075ad544
commit d103fc42f1
2 changed files with 42 additions and 0 deletions

View File

@ -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:

View File

@ -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):