mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
added unbind method for all widgets, fixed bind methods, fixed textbox configure
This commit is contained in:
parent
12f0942e73
commit
40474d6905
@ -86,7 +86,7 @@ class CTkButton(CTkBaseClass):
|
||||
self._canvas.bind("<Leave>", self._on_leave)
|
||||
self._canvas.bind("<Button-1>", self._clicked)
|
||||
self._canvas.bind("<Button-1>", self._clicked)
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
|
||||
# configure cursor and initial draw
|
||||
self._set_cursor()
|
||||
@ -412,3 +412,7 @@ class CTkButton(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, funcid)
|
||||
|
@ -367,3 +367,7 @@ class CTkCheckBox(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, funcid)
|
||||
|
@ -118,7 +118,7 @@ class CTkComboBox(CTkBaseClass):
|
||||
self._canvas.tag_bind("dropdown_arrow", "<Leave>", self._on_leave)
|
||||
self._canvas.tag_bind("right_parts", "<Button-1>", self._clicked)
|
||||
self._canvas.tag_bind("dropdown_arrow", "<Button-1>", self._clicked)
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
|
||||
if self._variable is not None:
|
||||
self._entry.configure(textvariable=self._variable)
|
||||
@ -351,5 +351,9 @@ class CTkComboBox(CTkBaseClass):
|
||||
self._open_dropdown_menu()
|
||||
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
""" called on the tkinter.Entry """
|
||||
return self._entry.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Entry """
|
||||
return self._entry.bind(sequence, funcid)
|
||||
|
@ -263,6 +263,10 @@ class CTkEntry(CTkBaseClass):
|
||||
""" called on the tkinter.Entry """
|
||||
return self._entry.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Entry """
|
||||
return self._entry.bind(sequence, funcid)
|
||||
|
||||
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
|
||||
|
@ -58,7 +58,7 @@ class CTkFrame(CTkBaseClass):
|
||||
self._draw_engine = DrawEngine(self._canvas)
|
||||
self._overwrite_preferred_drawing_method = overwrite_preferred_drawing_method
|
||||
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
|
||||
self._draw()
|
||||
|
||||
@ -161,3 +161,7 @@ class CTkFrame(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, funcid)
|
||||
|
@ -76,7 +76,7 @@ class CTkLabel(CTkBaseClass):
|
||||
|
||||
self._check_kwargs_empty(kwargs, raise_error=True)
|
||||
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
self._draw()
|
||||
|
||||
def _set_scaling(self, *args, **kwargs):
|
||||
@ -185,3 +185,7 @@ class CTkLabel(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Label """
|
||||
return self._text_label.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Label """
|
||||
return self._text_label.bind(sequence, funcid)
|
||||
|
@ -125,7 +125,7 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self._text_label.bind("<Button-1>", self._clicked)
|
||||
self._text_label.bind("<Button-1>", self._clicked)
|
||||
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
|
||||
self._draw() # initial draw
|
||||
|
||||
@ -303,6 +303,7 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
return self._command
|
||||
elif attribute_name == "dynamic_resizing":
|
||||
return self._dynamic_resizing
|
||||
|
||||
else:
|
||||
return super().cget(attribute_name)
|
||||
|
||||
@ -358,5 +359,9 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self._open_dropdown_menu()
|
||||
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
""" called on the tkinter.Label """
|
||||
return self._text_label.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Label """
|
||||
return self._text_label.bind(sequence, funcid)
|
||||
|
@ -81,7 +81,7 @@ class CTkProgressBar(CTkBaseClass):
|
||||
self._draw_engine = DrawEngine(self._canvas)
|
||||
|
||||
# Each time an item is resized due to pack position mode, the binding Configure is called on the widget
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
|
||||
self._draw() # initial draw
|
||||
|
||||
@ -222,6 +222,7 @@ class CTkProgressBar(CTkBaseClass):
|
||||
return self._determinate_speed
|
||||
elif attribute_name == "indeterminate_speed":
|
||||
return self._indeterminate_speed
|
||||
|
||||
else:
|
||||
return super().cget(attribute_name)
|
||||
|
||||
@ -285,3 +286,7 @@ class CTkProgressBar(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, funcid)
|
||||
|
@ -247,6 +247,7 @@ class CTkRadioButton(CTkBaseClass):
|
||||
return self._hover
|
||||
elif attribute_name == "command":
|
||||
return self._command
|
||||
|
||||
else:
|
||||
return super().cget(attribute_name)
|
||||
|
||||
@ -328,3 +329,7 @@ class CTkRadioButton(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, funcid)
|
||||
|
@ -75,7 +75,7 @@ class CTkScrollbar(CTkBaseClass):
|
||||
self._canvas.tag_bind("border_parts", "<Button-1>", self._clicked)
|
||||
self._canvas.bind("<B1-Motion>", self._clicked)
|
||||
self._canvas.bind("<MouseWheel>", self._mouse_scroll_event)
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
|
||||
self._draw()
|
||||
|
||||
@ -203,6 +203,7 @@ class CTkScrollbar(CTkBaseClass):
|
||||
return self._command
|
||||
elif attribute_name == "orientation":
|
||||
return self._orientation
|
||||
|
||||
else:
|
||||
return super().cget(attribute_name)
|
||||
|
||||
@ -252,3 +253,7 @@ class CTkScrollbar(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, funcid)
|
||||
|
@ -100,7 +100,7 @@ class CTkSlider(CTkBaseClass):
|
||||
self._canvas.bind("<B1-Motion>", self._clicked)
|
||||
|
||||
# Each time an item is resized due to pack position mode, the binding Configure is called on the widget
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
|
||||
self._set_cursor()
|
||||
self._draw() # initial draw
|
||||
@ -287,6 +287,7 @@ class CTkSlider(CTkBaseClass):
|
||||
return self._variable
|
||||
elif attribute_name == "orientation":
|
||||
return self._orientation
|
||||
|
||||
else:
|
||||
return super().cget(attribute_name)
|
||||
|
||||
@ -368,3 +369,7 @@ class CTkSlider(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, funcid)
|
||||
|
@ -308,6 +308,7 @@ class CTkSwitch(CTkBaseClass):
|
||||
return self._command
|
||||
elif attribute_name == "state":
|
||||
return self._state
|
||||
|
||||
else:
|
||||
return super().cget(attribute_name)
|
||||
|
||||
@ -377,3 +378,7 @@ class CTkSwitch(CTkBaseClass):
|
||||
def bind(self, sequence=None, command=None, add=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Canvas """
|
||||
return self._canvas.bind(sequence, funcid)
|
||||
|
@ -6,6 +6,8 @@ from ..theme_manager import ThemeManager
|
||||
from ..draw_engine import DrawEngine
|
||||
from .widget_base_class import CTkBaseClass
|
||||
|
||||
from .widget_helper_functions import pop_from_dict_by_set
|
||||
|
||||
|
||||
class CTkTextbox(CTkBaseClass):
|
||||
"""
|
||||
@ -13,6 +15,13 @@ class CTkTextbox(CTkBaseClass):
|
||||
For detailed information check out the documentation.
|
||||
"""
|
||||
|
||||
# attributes that are passed to and managed by the tkinter textbox only:
|
||||
_valid_tk_text_attributes = {"autoseparators", "cursor", "exportselection",
|
||||
"insertborderwidth", "insertofftime", "insertontime", "insertwidth",
|
||||
"maxundo", "padx", "pady", "selectborderwidth", "spacing1",
|
||||
"spacing2", "spacing3", "state", "tabs", "takefocus", "undo", "wrap",
|
||||
"xscrollcommand", "yscrollcommand"}
|
||||
|
||||
def __init__(self, *args,
|
||||
width: int = 200,
|
||||
height: int = 200,
|
||||
@ -66,12 +75,14 @@ class CTkTextbox(CTkBaseClass):
|
||||
font=self._font,
|
||||
highlightthickness=0,
|
||||
relief="flat",
|
||||
insertbackground=ThemeManager.single_color(("black", "white"), self._appearance_mode),
|
||||
insertbackground=ThemeManager.single_color(self._text_color, self._appearance_mode),
|
||||
bg=ThemeManager.single_color(self._fg_color, self._appearance_mode),
|
||||
**kwargs)
|
||||
**pop_from_dict_by_set(kwargs, self._valid_tk_text_attributes))
|
||||
self._textbox.grid(row=0, column=0, padx=self._corner_radius, pady=self._corner_radius, rowspan=1, columnspan=1, sticky="nsew")
|
||||
|
||||
self.bind('<Configure>', self._update_dimensions_event)
|
||||
self._check_kwargs_empty(kwargs, raise_error=True)
|
||||
|
||||
super().bind('<Configure>', self._update_dimensions_event)
|
||||
self._draw()
|
||||
|
||||
def _set_scaling(self, *args, **kwargs):
|
||||
@ -113,7 +124,7 @@ class CTkTextbox(CTkBaseClass):
|
||||
|
||||
self._textbox.configure(fg=ThemeManager.single_color(self._text_color, self._appearance_mode),
|
||||
bg=ThemeManager.single_color(self._fg_color, self._appearance_mode),
|
||||
insertbackground=ThemeManager.single_color(("black", "white"), self._appearance_mode))
|
||||
insertbackground=ThemeManager.single_color(self._text_color, self._appearance_mode))
|
||||
|
||||
self._canvas.tag_lower("inner_parts")
|
||||
self._canvas.tag_lower("border_parts")
|
||||
@ -153,12 +164,8 @@ class CTkTextbox(CTkBaseClass):
|
||||
if "font" in kwargs:
|
||||
raise ValueError("No attribute named font. Use text_font instead of font for CTk widgets")
|
||||
|
||||
if "bg_color" in kwargs:
|
||||
super().configure(bg_color=kwargs.pop("bg_color"), require_redraw=require_redraw)
|
||||
else:
|
||||
super().configure(require_redraw=require_redraw)
|
||||
|
||||
self._textbox.configure(**kwargs)
|
||||
self._textbox.configure(**pop_from_dict_by_set(kwargs, self._valid_tk_text_attributes))
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def cget(self, attribute_name: str) -> any:
|
||||
if attribute_name == "corner_radius":
|
||||
@ -175,6 +182,7 @@ class CTkTextbox(CTkBaseClass):
|
||||
|
||||
elif attribute_name == "font":
|
||||
return self._font
|
||||
|
||||
else:
|
||||
return super().cget(attribute_name)
|
||||
|
||||
@ -182,6 +190,10 @@ class CTkTextbox(CTkBaseClass):
|
||||
""" called on the tkinter.Text """
|
||||
return self._textbox.bind(sequence, command, add)
|
||||
|
||||
def unbind(self, sequence, funcid=None):
|
||||
""" called on the tkinter.Text """
|
||||
return self._textbox.bind(sequence, funcid)
|
||||
|
||||
def yview(self, *args):
|
||||
return self._textbox.yview(*args)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user