added focus wrapper functions to all widgets

This commit is contained in:
Tom Schimansky 2022-10-05 21:11:46 +02:00
parent 44323affa2
commit 4616561c13
15 changed files with 128 additions and 4 deletions

View File

@ -54,9 +54,9 @@ class CTkButton(CTkBaseClass):
# text, font, image
self._image = image
self._image_label = None
self._image_label: Union[tkinter.Label, None] = None
self._text = text
self._text_label = None
self._text_label: Union[tkinter.Label, None] = None
self._font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if font == "default_theme" else font
# callback and hover functionality
@ -65,7 +65,7 @@ class CTkButton(CTkBaseClass):
self._state = state
self._hover = hover
self._compound = compound
self._click_animation_running = False
self._click_animation_running: bool = False
# configure grid system (2x2)
self.grid_rowconfigure(0, weight=1)
@ -420,3 +420,12 @@ class CTkButton(CTkBaseClass):
canvas_bind_return, label_bind_return = funcid.split(" + ")
self._canvas.unbind(sequence, canvas_bind_return)
self._text_label.unbind(sequence, label_bind_return)
def focus(self):
return self._text_label.focus()
def focus_set(self):
return self._text_label.focus_set()
def focus_force(self):
return self._text_label.focus_force()

View File

@ -371,3 +371,12 @@ class CTkCheckBox(CTkBaseClass):
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Canvas """
return self._canvas.unbind(sequence, funcid)
def focus(self):
return self._text_label.focus()
def focus_set(self):
return self._text_label.focus_set()
def focus_force(self):
return self._text_label.focus_force()

View File

@ -357,3 +357,12 @@ class CTkComboBox(CTkBaseClass):
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Entry """
return self._entry.unbind(sequence, funcid)
def focus(self):
return self._entry.focus()
def focus_set(self):
return self._entry.focus_set()
def focus_force(self):
return self._entry.focus_force()

View File

@ -313,6 +313,9 @@ class CTkEntry(CTkBaseClass):
def focus(self):
return self._entry.focus()
def focus_set(self):
return self._entry.focus_set()
def focus_force(self):
return self._entry.focus_force()

View File

@ -90,6 +90,9 @@ class CTkFrame(CTkBaseClass):
def _draw(self, no_color_updates=False):
if not self._canvas.winfo_exists():
return
requires_recoloring = self._draw_engine.draw_rounded_rect_with_border(self._apply_widget_scaling(self._current_width),
self._apply_widget_scaling(self._current_height),
self._apply_widget_scaling(self._corner_radius),

View File

@ -193,3 +193,12 @@ class CTkLabel(CTkBaseClass):
canvas_bind_return, label_bind_return = funcid.split(" + ")
self._canvas.unbind(sequence, canvas_bind_return)
self._text_label.unbind(sequence, label_bind_return)
def focus(self):
return self._text_label.focus()
def focus_set(self):
return self._text_label.focus_set()
def focus_force(self):
return self._text_label.focus_force()

View File

@ -369,3 +369,12 @@ class CTkOptionMenu(CTkBaseClass):
canvas_bind_return, label_bind_return = funcid.split(" + ")
self._canvas.unbind(sequence, canvas_bind_return)
self._text_label.unbind(sequence, label_bind_return)
def focus(self):
return self._text_label.focus()
def focus_set(self):
return self._text_label.focus_set()
def focus_force(self):
return self._text_label.focus_force()

View File

@ -290,3 +290,12 @@ class CTkProgressBar(CTkBaseClass):
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Canvas """
return self._canvas.unbind(sequence, funcid)
def focus(self):
return self._canvas.focus()
def focus_set(self):
return self._canvas.focus_set()
def focus_force(self):
return self._canvas.focus_force()

View File

@ -333,3 +333,12 @@ class CTkRadioButton(CTkBaseClass):
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Canvas """
return self._canvas.unbind(sequence, funcid)
def focus(self):
return self._text_label.focus()
def focus_set(self):
return self._text_label.focus_set()
def focus_force(self):
return self._text_label.focus_force()

View File

@ -257,3 +257,12 @@ class CTkScrollbar(CTkBaseClass):
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Canvas """
return self._canvas.unbind(sequence, funcid)
def focus(self):
return self._canvas.focus()
def focus_set(self):
return self._canvas.focus_set()
def focus_force(self):
return self._canvas.focus_force()

View File

@ -373,3 +373,12 @@ class CTkSlider(CTkBaseClass):
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Canvas """
return self._canvas.unbind(sequence, funcid)
def focus(self):
return self._canvas.focus()
def focus_set(self):
return self._canvas.focus_set()
def focus_force(self):
return self._canvas.focus_force()

View File

@ -382,3 +382,12 @@ class CTkSwitch(CTkBaseClass):
def unbind(self, sequence, funcid=None):
""" called on the tkinter.Canvas """
return self._canvas.unbind(sequence, funcid)
def focus(self):
return self._text_label.focus()
def focus_set(self):
return self._text_label.focus_set()
def focus_force(self):
return self._text_label.focus_force()

View File

@ -0,0 +1,8 @@
from .widget_base_class import CTkBaseClass
class CTkTabview(CTkBaseClass):
def __init__(self, *args,
**kwargs):
super().__init__(*args, **kwargs)
pass

View File

@ -203,6 +203,9 @@ class CTkTextbox(CTkBaseClass):
def _draw(self, no_color_updates=False):
if not self._canvas.winfo_exists():
return
requires_recoloring = self._draw_engine.draw_rounded_rect_with_border(self._apply_widget_scaling(self._current_width),
self._apply_widget_scaling(self._current_height),
self._apply_widget_scaling(self._corner_radius),
@ -313,6 +316,15 @@ class CTkTextbox(CTkBaseClass):
""" called on the tkinter.Text """
return self._textbox.unbind(sequence, funcid)
def focus(self):
return self._textbox.focus()
def focus_set(self):
return self._textbox.focus_set()
def focus_force(self):
return self._textbox.focus_force()
def insert(self, index, text, tags=None):
self._check_if_scrollbars_needed()
return self._textbox.insert(index, text, tags)

View File

@ -10,7 +10,7 @@ app = customtkinter.CTk()
app.title("test_scrollbar.py")
app.geometry("800x1200")
app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure((0, 1, 2, 3), weight=1)
app.grid_columnconfigure((0, 1, 2, 3, 4), weight=1)
textbox_1 = customtkinter.CTkTextbox(app, fg_color=None, corner_radius=0, border_spacing=0)
textbox_1.grid(row=0, column=0, sticky="nsew")
@ -34,6 +34,7 @@ textbox_2.grid(row=2, column=0, sticky="nsew", padx=20, pady=20)
textbox_2.insert("0.0", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\n\n" * 20)
textbox_2 = customtkinter.CTkTextbox(frame_1, wrap="none", corner_radius=60, border_width=15)
#fg_color="blue", scrollbar_color="yellow", text_color="red")
textbox_2.grid(row=3, column=0, sticky="nsew", padx=20, pady=20)
textbox_2.insert("0.0", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\n\n" * 20)
@ -91,5 +92,12 @@ textbox_3 = customtkinter.CTkTextbox(frame_3, corner_radius=0, border_width=0, a
textbox_3.grid(row=4, column=0, sticky="nsew", padx=20, pady=20)
textbox_3.insert("0.0", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\n\n" * 20)
textbox_4 = customtkinter.CTkTextbox(app, fg_color=None, corner_radius=0)
textbox_4.grid(row=0, column=4, sticky="nsew")
textbox_4.insert("0.0", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\n\n" * 20)
scrollbar4 = customtkinter.CTkScrollbar(app, command=textbox_4.yview)
scrollbar4.grid(row=0, column=5, sticky="nsew")
textbox_4.configure(yscrollcommand=scrollbar4.set)
app.after(3000, lambda: customtkinter.set_appearance_mode("light"))
app.mainloop()