mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
added checkmark to CTkCheckbox
This commit is contained in:
parent
2ab5b7e19f
commit
9acd0c42df
Binary file not shown.
Binary file not shown.
@ -5,6 +5,7 @@
|
|||||||
"button_hover": ["#1A89BF", "#1673A1"],
|
"button_hover": ["#1A89BF", "#1673A1"],
|
||||||
"button_border": ["gray40", "gray70"],
|
"button_border": ["gray40", "gray70"],
|
||||||
"checkbox_border": ["gray40", "gray60"],
|
"checkbox_border": ["gray40", "gray60"],
|
||||||
|
"checkmark": ["white", "gray90"],
|
||||||
"entry": ["white", "gray24"],
|
"entry": ["white", "gray24"],
|
||||||
"entry_border": ["gray70", "gray32"],
|
"entry_border": ["gray70", "gray32"],
|
||||||
"entry_placeholder_text": ["gray52", "gray62"],
|
"entry_placeholder_text": ["gray52", "gray62"],
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
"button_hover": ["#A4BDE6", "#748BB3"],
|
"button_hover": ["#A4BDE6", "#748BB3"],
|
||||||
"button_border": ["gray40", "gray70"],
|
"button_border": ["gray40", "gray70"],
|
||||||
"checkbox_border": ["gray40", "gray60"],
|
"checkbox_border": ["gray40", "gray60"],
|
||||||
|
"checkmark": ["white", "gray90"],
|
||||||
"entry": ["white", "gray24"],
|
"entry": ["white", "gray24"],
|
||||||
"entry_border": ["gray70", "gray32"],
|
"entry_border": ["gray70", "gray32"],
|
||||||
"entry_placeholder_text": ["gray52", "gray62"],
|
"entry_placeholder_text": ["gray52", "gray62"],
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"button_hover": ["#0E9670", "#0D8A66"],
|
"button_hover": ["#0E9670", "#0D8A66"],
|
||||||
"button_border": ["gray40", "gray70"],
|
"button_border": ["gray40", "gray70"],
|
||||||
"checkbox_border": ["gray40", "gray60"],
|
"checkbox_border": ["gray40", "gray60"],
|
||||||
|
"checkmark": ["white", "gray90"],
|
||||||
"entry": ["white", "gray24"],
|
"entry": ["white", "gray24"],
|
||||||
"entry_border": ["gray70", "gray32"],
|
"entry_border": ["gray70", "gray32"],
|
||||||
"entry_placeholder_text": ["gray52", "gray62"],
|
"entry_placeholder_text": ["gray52", "gray62"],
|
||||||
|
@ -19,6 +19,7 @@ class CTkCheckBox(tkinter.Frame):
|
|||||||
hover_color="default_theme",
|
hover_color="default_theme",
|
||||||
border_color="default_theme",
|
border_color="default_theme",
|
||||||
border_width="default_theme",
|
border_width="default_theme",
|
||||||
|
checkmark_color="default_theme",
|
||||||
width=24,
|
width=24,
|
||||||
height=24,
|
height=24,
|
||||||
corner_radius="default_theme",
|
corner_radius="default_theme",
|
||||||
@ -63,6 +64,7 @@ class CTkCheckBox(tkinter.Frame):
|
|||||||
self.fg_color = CTkThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
self.fg_color = CTkThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
||||||
self.hover_color = CTkThemeManager.theme["color"]["button"] if hover_color == "default_theme" else hover_color
|
self.hover_color = CTkThemeManager.theme["color"]["button"] if hover_color == "default_theme" else hover_color
|
||||||
self.border_color = CTkThemeManager.theme["color"]["checkbox_border"] if border_color == "default_theme" else border_color
|
self.border_color = CTkThemeManager.theme["color"]["checkbox_border"] if border_color == "default_theme" else border_color
|
||||||
|
self.checkmark_color = CTkThemeManager.theme["color"]["checkmark"] if checkmark_color == "default_theme" else checkmark_color
|
||||||
|
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
@ -147,21 +149,33 @@ class CTkCheckBox(tkinter.Frame):
|
|||||||
def draw(self):
|
def draw(self):
|
||||||
requires_recoloring = self.draw_engine.draw_rounded_rect_with_border(self.width, self.height, self.corner_radius, self.border_width)
|
requires_recoloring = self.draw_engine.draw_rounded_rect_with_border(self.width, self.height, self.corner_radius, self.border_width)
|
||||||
|
|
||||||
|
if self.check_state is True:
|
||||||
|
self.draw_engine.draw_checkmark(self.width, self.height, self.height * 0.58)
|
||||||
|
else:
|
||||||
|
self.canvas.delete("checkmark")
|
||||||
|
|
||||||
self.canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
|
self.canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
|
||||||
self.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
|
self.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
|
||||||
|
|
||||||
if self.check_state is False:
|
if self.check_state is True:
|
||||||
self.canvas.itemconfig("inner_parts",
|
|
||||||
outline=CTkThemeManager.single_color(self.bg_color, self.appearance_mode),
|
|
||||||
fill=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
|
|
||||||
else:
|
|
||||||
self.canvas.itemconfig("inner_parts",
|
self.canvas.itemconfig("inner_parts",
|
||||||
outline=CTkThemeManager.single_color(self.fg_color, self.appearance_mode),
|
outline=CTkThemeManager.single_color(self.fg_color, self.appearance_mode),
|
||||||
fill=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
|
fill=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
|
||||||
|
self.canvas.itemconfig("border_parts",
|
||||||
|
outline=CTkThemeManager.single_color(self.fg_color, self.appearance_mode),
|
||||||
|
fill=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
|
||||||
|
|
||||||
self.canvas.itemconfig("border_parts",
|
if "create_line" in self.canvas.gettags("checkmark"):
|
||||||
outline=CTkThemeManager.single_color(self.border_color, self.appearance_mode),
|
self.canvas.itemconfig("checkmark", fill=CTkThemeManager.single_color(self.checkmark_color, self.appearance_mode))
|
||||||
fill=CTkThemeManager.single_color(self.border_color, self.appearance_mode))
|
else:
|
||||||
|
self.canvas.itemconfig("checkmark", fill=CTkThemeManager.single_color(self.checkmark_color, self.appearance_mode))
|
||||||
|
else:
|
||||||
|
self.canvas.itemconfig("inner_parts",
|
||||||
|
outline=CTkThemeManager.single_color(self.bg_color, self.appearance_mode),
|
||||||
|
fill=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
|
||||||
|
self.canvas.itemconfig("border_parts",
|
||||||
|
outline=CTkThemeManager.single_color(self.border_color, self.appearance_mode),
|
||||||
|
fill=CTkThemeManager.single_color(self.border_color, self.appearance_mode))
|
||||||
|
|
||||||
if self.text_label is None:
|
if self.text_label is None:
|
||||||
self.text_label = tkinter.Label(master=self,
|
self.text_label = tkinter.Label(master=self,
|
||||||
@ -299,14 +313,10 @@ class CTkCheckBox(tkinter.Frame):
|
|||||||
if self.state == tkinter.NORMAL:
|
if self.state == tkinter.NORMAL:
|
||||||
if self.check_state is True:
|
if self.check_state is True:
|
||||||
self.check_state = False
|
self.check_state = False
|
||||||
self.canvas.itemconfig("inner_parts",
|
self.draw()
|
||||||
fill=CTkThemeManager.single_color(self.bg_color, self.appearance_mode),
|
|
||||||
outline=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
|
|
||||||
else:
|
else:
|
||||||
self.check_state = True
|
self.check_state = True
|
||||||
self.canvas.itemconfig("inner_parts",
|
self.draw()
|
||||||
fill=CTkThemeManager.single_color(self.fg_color, self.appearance_mode),
|
|
||||||
outline=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
|
|
||||||
|
|
||||||
if self.function is not None:
|
if self.function is not None:
|
||||||
self.function()
|
self.function()
|
||||||
|
@ -15,6 +15,7 @@ class CTkDrawEngine:
|
|||||||
- draw_rounded_rect_with_border()
|
- draw_rounded_rect_with_border()
|
||||||
- draw_rounded_progress_bar_with_border()
|
- draw_rounded_progress_bar_with_border()
|
||||||
- draw_rounded_slider_with_border_and_button()
|
- draw_rounded_slider_with_border_and_button()
|
||||||
|
- draw_checkmark()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -627,3 +628,33 @@ class CTkDrawEngine:
|
|||||||
self._canvas.tag_raise("slider_parts")
|
self._canvas.tag_raise("slider_parts")
|
||||||
|
|
||||||
return requires_recoloring
|
return requires_recoloring
|
||||||
|
|
||||||
|
def draw_checkmark(self, width: int, height: int, size: Union[int, float]) -> bool:
|
||||||
|
""" Draws a rounded rectangle with a corner_radius and border_width on the canvas. The border elements have a 'border_parts' tag,
|
||||||
|
the main foreground elements have an 'inner_parts' tag to color the elements accordingly.
|
||||||
|
|
||||||
|
returns bool if recoloring is necessary """
|
||||||
|
|
||||||
|
size = round(size)
|
||||||
|
requires_recoloring = False
|
||||||
|
|
||||||
|
if self._rendering_method == "polygon_shapes" or self._rendering_method == "circle_shapes":
|
||||||
|
x, y, radius = width / 2, height / 2, size / 2.2
|
||||||
|
if not self._canvas.find_withtag("checkmark"):
|
||||||
|
self._canvas.create_line(0, 0, 0, 0, tags=("checkmark", "create_line"), width=round(height / 8), joinstyle=tkinter.MITER, capstyle=tkinter.ROUND)
|
||||||
|
self._canvas.tag_raise("checkmark")
|
||||||
|
requires_recoloring = True
|
||||||
|
|
||||||
|
self._canvas.coords("checkmark",
|
||||||
|
x + radius, y - radius,
|
||||||
|
x - radius / 4, y + radius,
|
||||||
|
x - radius, y + radius / 4)
|
||||||
|
elif self._rendering_method == "font_shapes":
|
||||||
|
if not self._canvas.find_withtag("checkmark"):
|
||||||
|
self._canvas.create_text(0, 0, text="Z", font=("CustomTkinter_shapes_font", -size), tags=("checkmark", "create_text"), anchor=tkinter.CENTER)
|
||||||
|
self._canvas.tag_raise("checkmark")
|
||||||
|
requires_recoloring = True
|
||||||
|
|
||||||
|
self._canvas.coords("checkmark", round(width / 2), round(height / 2))
|
||||||
|
|
||||||
|
return requires_recoloring
|
||||||
|
@ -4,7 +4,9 @@ import customtkinter
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
||||||
customtkinter.set_default_color_theme("dark-blue") # Themes: "blue" (standard), "green", "dark-blue"
|
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||||
|
|
||||||
|
customtkinter.CTkSettings.preferred_drawing_method = "circle_shapes"
|
||||||
|
|
||||||
|
|
||||||
class App(customtkinter.CTk):
|
class App(customtkinter.CTk):
|
||||||
|
Loading…
Reference in New Issue
Block a user