mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
added .config method to all widgets
This commit is contained in:
parent
d103fc42f1
commit
8b6f9a1d7e
@ -238,6 +238,9 @@ class CTkButton(CTkBaseClass):
|
||||
padx=max(self._apply_widget_scaling(self._corner_radius), self._apply_widget_scaling(self._border_width)),
|
||||
pady=(self._apply_widget_scaling(self._border_width), 2))
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "text" in kwargs:
|
||||
self._text = kwargs.pop("text")
|
||||
|
@ -175,6 +175,9 @@ class CTkCheckBox(CTkBaseClass):
|
||||
|
||||
self._text_label.configure(bg=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "text" in kwargs:
|
||||
self._text = kwargs.pop("text")
|
||||
|
@ -185,6 +185,9 @@ class CTkComboBox(CTkBaseClass):
|
||||
self._dropdown_menu.open(self.winfo_rootx(),
|
||||
self.winfo_rooty() + self._apply_widget_scaling(self._current_height + 0))
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "state" in kwargs:
|
||||
self._state = kwargs.pop("state")
|
||||
|
@ -140,8 +140,8 @@ class CTkEntry(CTkBaseClass):
|
||||
if self._placeholder_text_active:
|
||||
self._entry.config(fg=ThemeManager.single_color(self._placeholder_text_color, self._appearance_mode))
|
||||
|
||||
def bind(self, *args, **kwargs):
|
||||
self._entry.bind(*args, **kwargs)
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "state" in kwargs:
|
||||
@ -210,6 +210,9 @@ class CTkEntry(CTkBaseClass):
|
||||
|
||||
self._entry.configure(**kwargs) # pass remaining kwargs to entry
|
||||
|
||||
def bind(self, *args, **kwargs):
|
||||
self._entry.bind(*args, **kwargs)
|
||||
|
||||
def _activate_placeholder(self):
|
||||
if self._entry.get() == "" and self._placeholder_text is not None and (self._textvariable is None or self._textvariable == ""):
|
||||
self._placeholder_text_active = True
|
||||
|
@ -112,6 +112,9 @@ class CTkFrame(CTkBaseClass):
|
||||
self._canvas.tag_lower("inner_parts")
|
||||
self._canvas.tag_lower("border_parts")
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "fg_color" in kwargs:
|
||||
self._fg_color = kwargs.pop("fg_color")
|
||||
|
@ -110,8 +110,8 @@ class CTkLabel(CTkBaseClass):
|
||||
|
||||
self._canvas.configure(bg=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
||||
|
||||
def config(self, **kwargs):
|
||||
return self.configure(**kwargs)
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "anchor" in kwargs:
|
||||
|
@ -191,9 +191,8 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
|
||||
self._canvas.update_idletasks()
|
||||
|
||||
def _open_dropdown_menu(self):
|
||||
self._dropdown_menu.open(self.winfo_rootx(),
|
||||
self.winfo_rooty() + self._apply_widget_scaling(self._current_height + 0))
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "state" in kwargs:
|
||||
@ -268,6 +267,10 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def _open_dropdown_menu(self):
|
||||
self._dropdown_menu.open(self.winfo_rootx(),
|
||||
self.winfo_rooty() + self._apply_widget_scaling(self._current_height + 0))
|
||||
|
||||
def _on_enter(self, event=0):
|
||||
if self._hover is True and self._state == tkinter.NORMAL and len(self._values) > 0:
|
||||
# set color of inner button parts to hover color
|
||||
|
@ -150,6 +150,9 @@ class CTkProgressBar(CTkBaseClass):
|
||||
fill=ThemeManager.single_color(self._progress_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self._progress_color, self._appearance_mode))
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "fg_color" in kwargs:
|
||||
self._fg_color = kwargs.pop("fg_color")
|
||||
|
@ -156,6 +156,9 @@ class CTkRadioButton(CTkBaseClass):
|
||||
|
||||
self._text_label.configure(bg=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "text" in kwargs:
|
||||
self._text = kwargs.pop("text")
|
||||
|
@ -148,13 +148,8 @@ class CTkScrollbar(CTkBaseClass):
|
||||
|
||||
self._canvas.update_idletasks()
|
||||
|
||||
def set(self, start_value: float, end_value: float):
|
||||
self._start_value = float(start_value)
|
||||
self._end_value = float(end_value)
|
||||
self._draw()
|
||||
|
||||
def get(self):
|
||||
return self._start_value, self._end_value
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "fg_color" in kwargs:
|
||||
@ -222,3 +217,11 @@ class CTkScrollbar(CTkBaseClass):
|
||||
self._command('scroll', -int(event.delta/40), 'units')
|
||||
else:
|
||||
self._command('scroll', -event.delta, 'units')
|
||||
|
||||
def set(self, start_value: float, end_value: float):
|
||||
self._start_value = float(start_value)
|
||||
self._end_value = float(end_value)
|
||||
self._draw()
|
||||
|
||||
def get(self):
|
||||
return self._start_value, self._end_value
|
||||
|
@ -188,6 +188,9 @@ class CTkSlider(CTkBaseClass):
|
||||
fill=ThemeManager.single_color(self._button_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self._button_color, self._appearance_mode))
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "state" in kwargs:
|
||||
self._state = kwargs.pop("state")
|
||||
|
@ -205,68 +205,8 @@ class CTkSwitch(CTkBaseClass):
|
||||
|
||||
self._text_label.configure(bg=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
||||
|
||||
def toggle(self, event=None):
|
||||
if self._state is not tkinter.DISABLED:
|
||||
if self._check_state is True:
|
||||
self._check_state = False
|
||||
else:
|
||||
self._check_state = True
|
||||
|
||||
self._draw(no_color_updates=True)
|
||||
|
||||
if self._variable is not None:
|
||||
self._variable_callback_blocked = True
|
||||
self._variable.set(self._onvalue if self._check_state is True else self._offvalue)
|
||||
self._variable_callback_blocked = False
|
||||
|
||||
if self._command is not None:
|
||||
self._command()
|
||||
|
||||
def select(self, from_variable_callback=False):
|
||||
if self._state is not tkinter.DISABLED or from_variable_callback:
|
||||
self._check_state = True
|
||||
|
||||
self._draw(no_color_updates=True)
|
||||
|
||||
if self._variable is not None and not from_variable_callback:
|
||||
self._variable_callback_blocked = True
|
||||
self._variable.set(self._onvalue)
|
||||
self._variable_callback_blocked = False
|
||||
|
||||
def deselect(self, from_variable_callback=False):
|
||||
if self._state is not tkinter.DISABLED or from_variable_callback:
|
||||
self._check_state = False
|
||||
|
||||
self._draw(no_color_updates=True)
|
||||
|
||||
if self._variable is not None and not from_variable_callback:
|
||||
self._variable_callback_blocked = True
|
||||
self._variable.set(self._offvalue)
|
||||
self._variable_callback_blocked = False
|
||||
|
||||
def get(self) -> Union[int, str]:
|
||||
return self._onvalue if self._check_state is True else self._offvalue
|
||||
|
||||
def _on_enter(self, event=0):
|
||||
self._hover_state = True
|
||||
|
||||
if self._state is not tkinter.DISABLED:
|
||||
self._canvas.itemconfig("slider_parts",
|
||||
fill=ThemeManager.single_color(self._button_hover_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self._button_hover_color, self._appearance_mode))
|
||||
|
||||
def _on_leave(self, event=0):
|
||||
self._hover_state = False
|
||||
self._canvas.itemconfig("slider_parts",
|
||||
fill=ThemeManager.single_color(self._button_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self._button_color, self._appearance_mode))
|
||||
|
||||
def _variable_callback(self, var_name, index, mode):
|
||||
if not self._variable_callback_blocked:
|
||||
if self._variable.get() == self._onvalue:
|
||||
self.select(from_variable_callback=True)
|
||||
elif self._variable.get() == self._offvalue:
|
||||
self.deselect(from_variable_callback=True)
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "text" in kwargs:
|
||||
@ -329,3 +269,66 @@ class CTkSwitch(CTkBaseClass):
|
||||
require_redraw = True
|
||||
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def toggle(self, event=None):
|
||||
if self._state is not tkinter.DISABLED:
|
||||
if self._check_state is True:
|
||||
self._check_state = False
|
||||
else:
|
||||
self._check_state = True
|
||||
|
||||
self._draw(no_color_updates=True)
|
||||
|
||||
if self._variable is not None:
|
||||
self._variable_callback_blocked = True
|
||||
self._variable.set(self._onvalue if self._check_state is True else self._offvalue)
|
||||
self._variable_callback_blocked = False
|
||||
|
||||
if self._command is not None:
|
||||
self._command()
|
||||
|
||||
def select(self, from_variable_callback=False):
|
||||
if self._state is not tkinter.DISABLED or from_variable_callback:
|
||||
self._check_state = True
|
||||
|
||||
self._draw(no_color_updates=True)
|
||||
|
||||
if self._variable is not None and not from_variable_callback:
|
||||
self._variable_callback_blocked = True
|
||||
self._variable.set(self._onvalue)
|
||||
self._variable_callback_blocked = False
|
||||
|
||||
def deselect(self, from_variable_callback=False):
|
||||
if self._state is not tkinter.DISABLED or from_variable_callback:
|
||||
self._check_state = False
|
||||
|
||||
self._draw(no_color_updates=True)
|
||||
|
||||
if self._variable is not None and not from_variable_callback:
|
||||
self._variable_callback_blocked = True
|
||||
self._variable.set(self._offvalue)
|
||||
self._variable_callback_blocked = False
|
||||
|
||||
def get(self) -> Union[int, str]:
|
||||
return self._onvalue if self._check_state is True else self._offvalue
|
||||
|
||||
def _on_enter(self, event=0):
|
||||
self._hover_state = True
|
||||
|
||||
if self._state is not tkinter.DISABLED:
|
||||
self._canvas.itemconfig("slider_parts",
|
||||
fill=ThemeManager.single_color(self._button_hover_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self._button_hover_color, self._appearance_mode))
|
||||
|
||||
def _on_leave(self, event=0):
|
||||
self._hover_state = False
|
||||
self._canvas.itemconfig("slider_parts",
|
||||
fill=ThemeManager.single_color(self._button_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self._button_color, self._appearance_mode))
|
||||
|
||||
def _variable_callback(self, var_name, index, mode):
|
||||
if not self._variable_callback_blocked:
|
||||
if self._variable.get() == self._onvalue:
|
||||
self.select(from_variable_callback=True)
|
||||
elif self._variable.get() == self._offvalue:
|
||||
self.deselect(from_variable_callback=True)
|
||||
|
@ -116,29 +116,8 @@ class CTkTextbox(CTkBaseClass):
|
||||
self._canvas.tag_lower("inner_parts")
|
||||
self._canvas.tag_lower("border_parts")
|
||||
|
||||
def yview(self, *args):
|
||||
return self._textbox.yview(*args)
|
||||
|
||||
def xview(self, *args):
|
||||
return self._textbox.xview(*args)
|
||||
|
||||
def insert(self, *args, **kwargs):
|
||||
return self._textbox.insert(*args, **kwargs)
|
||||
|
||||
def focus(self):
|
||||
return self._textbox.focus()
|
||||
|
||||
def tag_add(self, *args, **kwargs):
|
||||
return self._textbox.tag_add(*args, **kwargs)
|
||||
|
||||
def tag_config(self, *args, **kwargs):
|
||||
return self._textbox.tag_config(*args, **kwargs)
|
||||
|
||||
def tag_configure(self, *args, **kwargs):
|
||||
return self._textbox.tag_configure(*args, **kwargs)
|
||||
|
||||
def tag_remove(self, *args, **kwargs):
|
||||
return self._textbox.tag_remove(*args, **kwargs)
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "fg_color" in kwargs:
|
||||
@ -181,3 +160,27 @@ class CTkTextbox(CTkBaseClass):
|
||||
super().configure(require_redraw=require_redraw)
|
||||
|
||||
self._textbox.configure(**kwargs)
|
||||
|
||||
def yview(self, *args):
|
||||
return self._textbox.yview(*args)
|
||||
|
||||
def xview(self, *args):
|
||||
return self._textbox.xview(*args)
|
||||
|
||||
def insert(self, *args, **kwargs):
|
||||
return self._textbox.insert(*args, **kwargs)
|
||||
|
||||
def focus(self):
|
||||
return self._textbox.focus()
|
||||
|
||||
def tag_add(self, *args, **kwargs):
|
||||
return self._textbox.tag_add(*args, **kwargs)
|
||||
|
||||
def tag_config(self, *args, **kwargs):
|
||||
return self._textbox.tag_config(*args, **kwargs)
|
||||
|
||||
def tag_configure(self, *args, **kwargs):
|
||||
return self._textbox.tag_configure(*args, **kwargs)
|
||||
|
||||
def tag_remove(self, *args, **kwargs):
|
||||
return self._textbox.tag_remove(*args, **kwargs)
|
||||
|
@ -102,6 +102,9 @@ class DropdownMenu(tkinter.Menu):
|
||||
else: # Linux
|
||||
self.tk_popup(int(x), int(y))
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
if "values" in kwargs:
|
||||
self._values = kwargs.pop("values")
|
||||
|
@ -117,6 +117,9 @@ class CTkBaseClass(tkinter.Frame):
|
||||
|
||||
return scaled_kwargs
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
return self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
""" basic configure with _bg_color support, to be overridden """
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user