mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
b891032e2e | |||
28308065bc | |||
d4ae8cab7d | |||
ec3fdc40ff | |||
a7b175ae65 | |||
43900c7fef | |||
79ecd2e946 | |||
3b259e4d01 | |||
7a99aa318c | |||
9ff6cc8268 | |||
3a1d12f8ea | |||
45e47f5970 | |||
0e510dec53 | |||
fc952294f0 | |||
d8b5104028 | |||
20e16969f2 | |||
a86dbd4d07 | |||
413cedd093 | |||
91e7e3077c |
@ -1,4 +1,4 @@
|
|||||||
__version__ = "4.3.0"
|
__version__ = "4.5.0"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -14,7 +14,15 @@ from .font_manager import FontManager
|
|||||||
from .draw_engine import DrawEngine
|
from .draw_engine import DrawEngine
|
||||||
|
|
||||||
AppearanceModeTracker.init_appearance_mode()
|
AppearanceModeTracker.init_appearance_mode()
|
||||||
ThemeManager.load_theme("blue") # load default theme
|
|
||||||
|
# load default blue theme
|
||||||
|
try:
|
||||||
|
ThemeManager.load_theme("blue")
|
||||||
|
except FileNotFoundError as err:
|
||||||
|
raise FileNotFoundError(f"{err}\n\nThe .json theme file for CustomTkinter could not be found.\n" +
|
||||||
|
f"If packaging with pyinstaller was used, have a look at the wiki:\n" +
|
||||||
|
f"https://github.com/TomSchimansky/CustomTkinter/wiki/Packaging#windows-pyinstaller-auto-py-to-exe")
|
||||||
|
|
||||||
FontManager.init_font_manager()
|
FontManager.init_font_manager()
|
||||||
|
|
||||||
# determine draw method based on current platform
|
# determine draw method based on current platform
|
||||||
@ -53,6 +61,7 @@ from .widgets.ctk_canvas import CTkCanvas
|
|||||||
from .widgets.ctk_switch import CTkSwitch
|
from .widgets.ctk_switch import CTkSwitch
|
||||||
from .widgets.ctk_optionmenu import CTkOptionMenu
|
from .widgets.ctk_optionmenu import CTkOptionMenu
|
||||||
from .widgets.ctk_combobox import CTkComboBox
|
from .widgets.ctk_combobox import CTkComboBox
|
||||||
|
from .widgets.ctk_scrollbar import CTkScrollbar
|
||||||
|
|
||||||
# import windows
|
# import windows
|
||||||
from .windows.ctk_tk import CTk
|
from .windows.ctk_tk import CTk
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"entry_placeholder_text": ["gray52", "gray62"],
|
"entry_placeholder_text": ["gray52", "gray62"],
|
||||||
"frame_border": ["#979DA2", "#1F2122"],
|
"frame_border": ["#979DA2", "#1F2122"],
|
||||||
"frame_low": ["#D1D5D8", "#2A2D2E"],
|
"frame_low": ["#D1D5D8", "#2A2D2E"],
|
||||||
"frame_high": ["#D7D8D9", "#343638"],
|
"frame_high": ["#C0C2C5", "#343638"],
|
||||||
"label": [null, null],
|
"label": [null, null],
|
||||||
"text": ["gray10", "#DCE4EE"],
|
"text": ["gray10", "#DCE4EE"],
|
||||||
"text_disabled": ["gray60", "#777B80"],
|
"text_disabled": ["gray60", "#777B80"],
|
||||||
@ -31,9 +31,11 @@
|
|||||||
"optionmenu_button_hover": ["#27577D", "#203A4F"],
|
"optionmenu_button_hover": ["#27577D", "#203A4F"],
|
||||||
"combobox_border": ["#979DA2", "#565B5E"],
|
"combobox_border": ["#979DA2", "#565B5E"],
|
||||||
"combobox_button_hover": ["#6E7174", "#7A848D"],
|
"combobox_button_hover": ["#6E7174", "#7A848D"],
|
||||||
"dropdown_color": ["#A8ACB1", "#535353"],
|
"dropdown_color": ["gray90", "gray20"],
|
||||||
"dropdown_hover": ["#D6DCE2", "#393D40"],
|
"dropdown_hover": ["gray75", "gray28"],
|
||||||
"dropdown_text": ["gray10", "#DCE4EE"]
|
"dropdown_text": ["gray10", "#DCE4EE"],
|
||||||
|
"scrollbar_button": ["gray55", "gray41"],
|
||||||
|
"scrollbar_button_hover": ["gray40", "gray53"]
|
||||||
},
|
},
|
||||||
"text": {
|
"text": {
|
||||||
"macOS": {
|
"macOS": {
|
||||||
@ -70,6 +72,8 @@
|
|||||||
"switch_border_width": 3,
|
"switch_border_width": 3,
|
||||||
"switch_corner_radius": 1000,
|
"switch_corner_radius": 1000,
|
||||||
"switch_button_corner_radius": 1000,
|
"switch_button_corner_radius": 1000,
|
||||||
"switch_button_length": 0
|
"switch_button_length": 0,
|
||||||
|
"scrollbar_corner_radius": 1000,
|
||||||
|
"scrollbar_border_spacing": 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,11 @@
|
|||||||
"optionmenu_button_hover": ["#27577D", "#203A4F"],
|
"optionmenu_button_hover": ["#27577D", "#203A4F"],
|
||||||
"combobox_border": ["gray70", "gray32"],
|
"combobox_border": ["gray70", "gray32"],
|
||||||
"combobox_button_hover": ["#6E7174", "#7A848D"],
|
"combobox_button_hover": ["#6E7174", "#7A848D"],
|
||||||
"dropdown_color": ["#A8ACB1", "#535353"],
|
"dropdown_color": ["gray90", "gray20"],
|
||||||
"dropdown_hover": ["#D6DCE2", "#393D40"],
|
"dropdown_hover": ["gray75", "gray28"],
|
||||||
"dropdown_text": ["gray12", "gray90"]
|
"dropdown_text": ["gray10", "#DCE4EE"],
|
||||||
|
"scrollbar_button": ["gray55", "gray41"],
|
||||||
|
"scrollbar_button_hover": ["gray40", "gray53"]
|
||||||
},
|
},
|
||||||
"text": {
|
"text": {
|
||||||
"macOS": {
|
"macOS": {
|
||||||
|
@ -31,9 +31,11 @@
|
|||||||
"optionmenu_button_hover":["gray40", "gray70"],
|
"optionmenu_button_hover":["gray40", "gray70"],
|
||||||
"combobox_border": ["gray70", "gray32"],
|
"combobox_border": ["gray70", "gray32"],
|
||||||
"combobox_button_hover": ["#6E7174", "#7A848D"],
|
"combobox_button_hover": ["#6E7174", "#7A848D"],
|
||||||
"dropdown_color": ["#A8ACB1", "#535353"],
|
"dropdown_color": ["gray90", "gray20"],
|
||||||
"dropdown_hover": ["#D6DCE2", "#393D40"],
|
"dropdown_hover": ["gray75", "gray28"],
|
||||||
"dropdown_text": ["gray12", "gray90"]
|
"dropdown_text": ["gray10", "#DCE4EE"],
|
||||||
|
"scrollbar_button": ["gray55", "gray41"],
|
||||||
|
"scrollbar_button_hover": ["gray40", "gray53"]
|
||||||
},
|
},
|
||||||
"text": {
|
"text": {
|
||||||
"macOS": {
|
"macOS": {
|
||||||
|
@ -27,7 +27,15 @@
|
|||||||
"switch_progress": ["#00e6c3", "#00e6c3"],
|
"switch_progress": ["#00e6c3", "#00e6c3"],
|
||||||
"switch_button": ["#2e324a", "#2e324a"],
|
"switch_button": ["#2e324a", "#2e324a"],
|
||||||
"switch_button_hover": ["#2e324a", "#2e324a"],
|
"switch_button_hover": ["#2e324a", "#2e324a"],
|
||||||
"darken_factor": 0.1
|
"optionmenu_button": ["#36719F", "#144870"],
|
||||||
|
"optionmenu_button_hover": ["#27577D", "#203A4F"],
|
||||||
|
"combobox_border": ["#979DA2", "#565B5E"],
|
||||||
|
"combobox_button_hover": ["#6E7174", "#7A848D"],
|
||||||
|
"dropdown_color": ["gray90", "gray20"],
|
||||||
|
"dropdown_hover": ["gray75", "gray28"],
|
||||||
|
"dropdown_text": ["gray10", "#DCE4EE"],
|
||||||
|
"scrollbar_button": ["gray55", "gray41"],
|
||||||
|
"scrollbar_button_hover": ["gray40", "gray53"]
|
||||||
},
|
},
|
||||||
"text": {
|
"text": {
|
||||||
"macOS": {
|
"macOS": {
|
||||||
|
@ -20,6 +20,7 @@ class DrawEngine:
|
|||||||
- draw_rounded_rect_with_border_vertical_split()
|
- draw_rounded_rect_with_border_vertical_split()
|
||||||
- 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_rounded_scrollbar()
|
||||||
- draw_checkmark()
|
- draw_checkmark()
|
||||||
- draw_dropdown_arrow()
|
- draw_dropdown_arrow()
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ class DrawEngine:
|
|||||||
else:
|
else:
|
||||||
return round(user_corner_radius)
|
return round(user_corner_radius)
|
||||||
|
|
||||||
# optimize forx drawing with antialiased font shapes
|
# optimize for drawing with antialiased font shapes
|
||||||
elif self.preferred_drawing_method == "font_shapes":
|
elif self.preferred_drawing_method == "font_shapes":
|
||||||
return round(user_corner_radius)
|
return round(user_corner_radius)
|
||||||
|
|
||||||
@ -397,8 +398,8 @@ class DrawEngine:
|
|||||||
if not self._canvas.find_withtag("border_parts"):
|
if not self._canvas.find_withtag("border_parts"):
|
||||||
self._canvas.create_polygon((0, 0, 0, 0), tags=("border_line_left_1", "border_parts_left", "border_parts", "left_parts"))
|
self._canvas.create_polygon((0, 0, 0, 0), tags=("border_line_left_1", "border_parts_left", "border_parts", "left_parts"))
|
||||||
self._canvas.create_polygon((0, 0, 0, 0), tags=("border_line_right_1", "border_parts_right", "border_parts", "right_parts"))
|
self._canvas.create_polygon((0, 0, 0, 0), tags=("border_line_right_1", "border_parts_right", "border_parts", "right_parts"))
|
||||||
self._canvas.create_rectangle((0, 0, 0, 0), tags=("border_rect_left_1", "border_parts_left", "border_parts", "left_parts"))
|
self._canvas.create_rectangle((0, 0, 0, 0), tags=("border_rect_left_1", "border_parts_left", "border_parts", "left_parts"), width=0)
|
||||||
self._canvas.create_rectangle((0, 0, 0, 0), tags=("border_rect_right_1", "border_parts_right", "border_parts", "right_parts"))
|
self._canvas.create_rectangle((0, 0, 0, 0), tags=("border_rect_right_1", "border_parts_right", "border_parts", "right_parts"), width=0)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
|
|
||||||
self._canvas.coords("border_line_left_1",
|
self._canvas.coords("border_line_left_1",
|
||||||
@ -490,22 +491,27 @@ class DrawEngine:
|
|||||||
# create canvas border corner parts if not already created, but only if needed, and delete if not needed
|
# create canvas border corner parts if not already created, but only if needed, and delete if not needed
|
||||||
if not self._canvas.find_withtag("border_oval_1_a") and "border_oval_1" not in exclude_parts:
|
if not self._canvas.find_withtag("border_oval_1_a") and "border_oval_1" not in exclude_parts:
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_1_a", "border_corner_part", "border_parts_left", "border_parts", "left_parts"), anchor=tkinter.CENTER)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_1_a", "border_corner_part", "border_parts_left", "border_parts", "left_parts"), anchor=tkinter.CENTER)
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_1_b", "border_corner_part", "border_parts_left", "border_parts", "left_parts"), anchor=tkinter.CENTER, angle=180)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_1_b", "border_corner_part", "border_parts_left", "border_parts", "left_parts"), anchor=tkinter.CENTER,
|
||||||
|
angle=180)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
elif self._canvas.find_withtag("border_oval_1_a") and "border_oval_1" in exclude_parts:
|
elif self._canvas.find_withtag("border_oval_1_a") and "border_oval_1" in exclude_parts:
|
||||||
self._canvas.delete("border_oval_1_a", "border_oval_1_b")
|
self._canvas.delete("border_oval_1_a", "border_oval_1_b")
|
||||||
|
|
||||||
if not self._canvas.find_withtag("border_oval_2_a") and width > 2 * corner_radius and "border_oval_2" not in exclude_parts:
|
if not self._canvas.find_withtag("border_oval_2_a") and width > 2 * corner_radius and "border_oval_2" not in exclude_parts:
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_2_a", "border_corner_part", "border_parts_right", "border_parts", "right_parts"), anchor=tkinter.CENTER)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_2_a", "border_corner_part", "border_parts_right", "border_parts", "right_parts"),
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_2_b", "border_corner_part", "border_parts_right", "border_parts", "right_parts"), anchor=tkinter.CENTER, angle=180)
|
anchor=tkinter.CENTER)
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_2_b", "border_corner_part", "border_parts_right", "border_parts", "right_parts"),
|
||||||
|
anchor=tkinter.CENTER, angle=180)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
elif self._canvas.find_withtag("border_oval_2_a") and (not width > 2 * corner_radius or "border_oval_2" in exclude_parts):
|
elif self._canvas.find_withtag("border_oval_2_a") and (not width > 2 * corner_radius or "border_oval_2" in exclude_parts):
|
||||||
self._canvas.delete("border_oval_2_a", "border_oval_2_b")
|
self._canvas.delete("border_oval_2_a", "border_oval_2_b")
|
||||||
|
|
||||||
if not self._canvas.find_withtag("border_oval_3_a") and height > 2 * corner_radius \
|
if not self._canvas.find_withtag("border_oval_3_a") and height > 2 * corner_radius \
|
||||||
and width > 2 * corner_radius and "border_oval_3" not in exclude_parts:
|
and width > 2 * corner_radius and "border_oval_3" not in exclude_parts:
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_3_a", "border_corner_part", "border_parts_right", "border_parts", "right_parts"), anchor=tkinter.CENTER)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_3_a", "border_corner_part", "border_parts_right", "border_parts", "right_parts"),
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_3_b", "border_corner_part", "border_parts_right", "border_parts", "right_parts"), anchor=tkinter.CENTER, angle=180)
|
anchor=tkinter.CENTER)
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_3_b", "border_corner_part", "border_parts_right", "border_parts", "right_parts"),
|
||||||
|
anchor=tkinter.CENTER, angle=180)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
elif self._canvas.find_withtag("border_oval_3_a") and (not (height > 2 * corner_radius
|
elif self._canvas.find_withtag("border_oval_3_a") and (not (height > 2 * corner_radius
|
||||||
and width > 2 * corner_radius) or "border_oval_3" in exclude_parts):
|
and width > 2 * corner_radius) or "border_oval_3" in exclude_parts):
|
||||||
@ -513,7 +519,8 @@ class DrawEngine:
|
|||||||
|
|
||||||
if not self._canvas.find_withtag("border_oval_4_a") and height > 2 * corner_radius and "border_oval_4" not in exclude_parts:
|
if not self._canvas.find_withtag("border_oval_4_a") and height > 2 * corner_radius and "border_oval_4" not in exclude_parts:
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_4_a", "border_corner_part", "border_parts_left", "border_parts", "left_parts"), anchor=tkinter.CENTER)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_4_a", "border_corner_part", "border_parts_left", "border_parts", "left_parts"), anchor=tkinter.CENTER)
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_4_b", "border_corner_part", "border_parts_left", "border_parts", "left_parts"), anchor=tkinter.CENTER, angle=180)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("border_oval_4_b", "border_corner_part", "border_parts_left", "border_parts", "left_parts"), anchor=tkinter.CENTER,
|
||||||
|
angle=180)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
elif self._canvas.find_withtag("border_oval_4_a") and (not height > 2 * corner_radius or "border_oval_4" in exclude_parts):
|
elif self._canvas.find_withtag("border_oval_4_a") and (not height > 2 * corner_radius or "border_oval_4" in exclude_parts):
|
||||||
self._canvas.delete("border_oval_4_a", "border_oval_4_b")
|
self._canvas.delete("border_oval_4_a", "border_oval_4_b")
|
||||||
@ -554,14 +561,16 @@ class DrawEngine:
|
|||||||
# create canvas border corner parts if not already created, but only if they're needed and delete if not needed
|
# create canvas border corner parts if not already created, but only if they're needed and delete if not needed
|
||||||
if not self._canvas.find_withtag("inner_oval_1_a") and "inner_oval_1" not in exclude_parts:
|
if not self._canvas.find_withtag("inner_oval_1_a") and "inner_oval_1" not in exclude_parts:
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_1_a", "inner_corner_part", "inner_parts_left", "inner_parts", "left_parts"), anchor=tkinter.CENTER)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_1_a", "inner_corner_part", "inner_parts_left", "inner_parts", "left_parts"), anchor=tkinter.CENTER)
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_1_b", "inner_corner_part", "inner_parts_left", "inner_parts", "left_parts"), anchor=tkinter.CENTER, angle=180)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_1_b", "inner_corner_part", "inner_parts_left", "inner_parts", "left_parts"), anchor=tkinter.CENTER,
|
||||||
|
angle=180)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
elif self._canvas.find_withtag("inner_oval_1_a") and "inner_oval_1" in exclude_parts:
|
elif self._canvas.find_withtag("inner_oval_1_a") and "inner_oval_1" in exclude_parts:
|
||||||
self._canvas.delete("inner_oval_1_a", "inner_oval_1_b")
|
self._canvas.delete("inner_oval_1_a", "inner_oval_1_b")
|
||||||
|
|
||||||
if not self._canvas.find_withtag("inner_oval_2_a") and width - (2 * border_width) > 2 * inner_corner_radius and "inner_oval_2" not in exclude_parts:
|
if not self._canvas.find_withtag("inner_oval_2_a") and width - (2 * border_width) > 2 * inner_corner_radius and "inner_oval_2" not in exclude_parts:
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_2_a", "inner_corner_part", "inner_parts_right", "inner_parts", "right_parts"), anchor=tkinter.CENTER)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_2_a", "inner_corner_part", "inner_parts_right", "inner_parts", "right_parts"), anchor=tkinter.CENTER)
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_2_b", "inner_corner_part", "inner_parts_right", "inner_parts", "right_parts"), anchor=tkinter.CENTER, angle=180)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_2_b", "inner_corner_part", "inner_parts_right", "inner_parts", "right_parts"), anchor=tkinter.CENTER,
|
||||||
|
angle=180)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
elif self._canvas.find_withtag("inner_oval_2_a") and (not width - (2 * border_width) > 2 * inner_corner_radius or "inner_oval_2" in exclude_parts):
|
elif self._canvas.find_withtag("inner_oval_2_a") and (not width - (2 * border_width) > 2 * inner_corner_radius or "inner_oval_2" in exclude_parts):
|
||||||
self._canvas.delete("inner_oval_2_a", "inner_oval_2_b")
|
self._canvas.delete("inner_oval_2_a", "inner_oval_2_b")
|
||||||
@ -569,7 +578,8 @@ class DrawEngine:
|
|||||||
if not self._canvas.find_withtag("inner_oval_3_a") and height - (2 * border_width) > 2 * inner_corner_radius \
|
if not self._canvas.find_withtag("inner_oval_3_a") and height - (2 * border_width) > 2 * inner_corner_radius \
|
||||||
and width - (2 * border_width) > 2 * inner_corner_radius and "inner_oval_3" not in exclude_parts:
|
and width - (2 * border_width) > 2 * inner_corner_radius and "inner_oval_3" not in exclude_parts:
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_3_a", "inner_corner_part", "inner_parts_right", "inner_parts", "right_parts"), anchor=tkinter.CENTER)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_3_a", "inner_corner_part", "inner_parts_right", "inner_parts", "right_parts"), anchor=tkinter.CENTER)
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_3_b", "inner_corner_part", "inner_parts_right", "inner_parts", "right_parts"), anchor=tkinter.CENTER, angle=180)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_3_b", "inner_corner_part", "inner_parts_right", "inner_parts", "right_parts"), anchor=tkinter.CENTER,
|
||||||
|
angle=180)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
elif self._canvas.find_withtag("inner_oval_3_a") and (not (height - (2 * border_width) > 2 * inner_corner_radius
|
elif self._canvas.find_withtag("inner_oval_3_a") and (not (height - (2 * border_width) > 2 * inner_corner_radius
|
||||||
and width - (2 * border_width) > 2 * inner_corner_radius) or "inner_oval_3" in exclude_parts):
|
and width - (2 * border_width) > 2 * inner_corner_radius) or "inner_oval_3" in exclude_parts):
|
||||||
@ -577,7 +587,8 @@ class DrawEngine:
|
|||||||
|
|
||||||
if not self._canvas.find_withtag("inner_oval_4_a") and height - (2 * border_width) > 2 * inner_corner_radius and "inner_oval_4" not in exclude_parts:
|
if not self._canvas.find_withtag("inner_oval_4_a") and height - (2 * border_width) > 2 * inner_corner_radius and "inner_oval_4" not in exclude_parts:
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_4_a", "inner_corner_part", "inner_parts_left", "inner_parts", "left_parts"), anchor=tkinter.CENTER)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_4_a", "inner_corner_part", "inner_parts_left", "inner_parts", "left_parts"), anchor=tkinter.CENTER)
|
||||||
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_4_b", "inner_corner_part", "inner_parts_left", "inner_parts", "left_parts"), anchor=tkinter.CENTER, angle=180)
|
self._canvas.create_aa_circle(0, 0, 0, tags=("inner_oval_4_b", "inner_corner_part", "inner_parts_left", "inner_parts", "left_parts"), anchor=tkinter.CENTER,
|
||||||
|
angle=180)
|
||||||
requires_recoloring = True
|
requires_recoloring = True
|
||||||
elif self._canvas.find_withtag("inner_oval_4_a") and (not height - (2 * border_width) > 2 * inner_corner_radius or "inner_oval_4" in exclude_parts):
|
elif self._canvas.find_withtag("inner_oval_4_a") and (not height - (2 * border_width) > 2 * inner_corner_radius or "inner_oval_4" in exclude_parts):
|
||||||
self._canvas.delete("inner_oval_4_a", "inner_oval_4_b")
|
self._canvas.delete("inner_oval_4_a", "inner_oval_4_b")
|
||||||
@ -959,6 +970,146 @@ class DrawEngine:
|
|||||||
|
|
||||||
return requires_recoloring
|
return requires_recoloring
|
||||||
|
|
||||||
|
def draw_rounded_scrollbar(self, width: Union[float, int], height: Union[float, int], corner_radius: Union[float, int],
|
||||||
|
border_spacing: Union[float, int], start_value: float, end_value: float, orientation: str) -> bool:
|
||||||
|
width = math.floor(width / 2) * 2 # round _current_width and _current_height and restrict them to even values only
|
||||||
|
height = math.floor(height / 2) * 2
|
||||||
|
|
||||||
|
if corner_radius > width / 2 or corner_radius > height / 2: # restrict corner_radius if it's too larger
|
||||||
|
corner_radius = min(width / 2, height / 2)
|
||||||
|
|
||||||
|
border_spacing = round(border_spacing)
|
||||||
|
corner_radius = self.__calc_optimal_corner_radius(corner_radius) # optimize corner_radius for different drawing methods (different rounding)
|
||||||
|
|
||||||
|
if corner_radius >= border_spacing:
|
||||||
|
inner_corner_radius = corner_radius - border_spacing
|
||||||
|
else:
|
||||||
|
inner_corner_radius = 0
|
||||||
|
|
||||||
|
if self.preferred_drawing_method == "polygon_shapes" or self.preferred_drawing_method == "circle_shapes":
|
||||||
|
return self.__draw_rounded_scrollbar_polygon_shapes(width, height, corner_radius, inner_corner_radius,
|
||||||
|
start_value, end_value, orientation)
|
||||||
|
elif self.preferred_drawing_method == "font_shapes":
|
||||||
|
return self.__draw_rounded_scrollbar_font_shapes(width, height, corner_radius, inner_corner_radius,
|
||||||
|
start_value, end_value, orientation)
|
||||||
|
|
||||||
|
def __draw_rounded_scrollbar_polygon_shapes(self, width: int, height: int, corner_radius: int, inner_corner_radius: int,
|
||||||
|
start_value: float, end_value: float, orientation: str) -> bool:
|
||||||
|
requires_recoloring = False
|
||||||
|
|
||||||
|
if not self._canvas.find_withtag("border_parts"):
|
||||||
|
self._canvas.create_rectangle(0, 0, 0, 0, tags=("border_rectangle_1", "border_parts"), width=0)
|
||||||
|
requires_recoloring = True
|
||||||
|
self._canvas.coords("border_rectangle_1", 0, 0, width, height)
|
||||||
|
|
||||||
|
if not self._canvas.find_withtag("scrollbar_parts"):
|
||||||
|
self._canvas.create_polygon((0, 0, 0, 0), tags=("scrollbar_polygon_1", "scrollbar_parts"), joinstyle=tkinter.ROUND)
|
||||||
|
self._canvas.tag_raise("scrollbar_parts", "border_parts")
|
||||||
|
requires_recoloring = True
|
||||||
|
|
||||||
|
if orientation == "vertical":
|
||||||
|
self._canvas.coords("scrollbar_polygon_1",
|
||||||
|
corner_radius, corner_radius + (height - 2 * corner_radius) * start_value,
|
||||||
|
width - corner_radius, corner_radius + (height - 2 * corner_radius) * start_value,
|
||||||
|
width - corner_radius, corner_radius + (height - 2 * corner_radius) * end_value,
|
||||||
|
corner_radius, corner_radius + (height - 2 * corner_radius) * end_value)
|
||||||
|
elif orientation == "horizontal":
|
||||||
|
self._canvas.coords("scrollbar_polygon_1",
|
||||||
|
corner_radius + (width - 2 * corner_radius) * start_value, corner_radius,
|
||||||
|
corner_radius + (width - 2 * corner_radius) * end_value, corner_radius,
|
||||||
|
corner_radius + (width - 2 * corner_radius) * end_value, height - corner_radius,
|
||||||
|
corner_radius + (width - 2 * corner_radius) * start_value, height - corner_radius,)
|
||||||
|
|
||||||
|
self._canvas.itemconfig("scrollbar_polygon_1", width=inner_corner_radius * 2)
|
||||||
|
|
||||||
|
return requires_recoloring
|
||||||
|
|
||||||
|
def __draw_rounded_scrollbar_font_shapes(self, width: int, height: int, corner_radius: int, inner_corner_radius: int,
|
||||||
|
start_value: float, end_value: float, orientation: str) -> bool:
|
||||||
|
requires_recoloring = False
|
||||||
|
|
||||||
|
if not self._canvas.find_withtag("border_parts"):
|
||||||
|
self._canvas.create_rectangle(0, 0, 0, 0, tags=("border_rectangle_1", "border_parts"), width=0)
|
||||||
|
requires_recoloring = True
|
||||||
|
self._canvas.coords("border_rectangle_1", 0, 0, width, height)
|
||||||
|
|
||||||
|
if inner_corner_radius > 0:
|
||||||
|
if not self._canvas.find_withtag("scrollbar_oval_1_a"):
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("scrollbar_oval_1_a", "scrollbar_corner_part", "scrollbar_parts"), anchor=tkinter.CENTER)
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("scrollbar_oval_1_b", "scrollbar_corner_part", "scrollbar_parts"), anchor=tkinter.CENTER, angle=180)
|
||||||
|
requires_recoloring = True
|
||||||
|
|
||||||
|
if not self._canvas.find_withtag("scrollbar_oval_2_a") and width > 2 * corner_radius:
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("scrollbar_oval_2_a", "scrollbar_corner_part", "scrollbar_parts"), anchor=tkinter.CENTER)
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("scrollbar_oval_2_b", "scrollbar_corner_part", "scrollbar_parts"), anchor=tkinter.CENTER, angle=180)
|
||||||
|
requires_recoloring = True
|
||||||
|
elif self._canvas.find_withtag("scrollbar_oval_2_a") and not width > 2 * corner_radius:
|
||||||
|
self._canvas.delete("scrollbar_oval_2_a", "scrollbar_oval_2_b")
|
||||||
|
|
||||||
|
if not self._canvas.find_withtag("scrollbar_oval_3_a") and height > 2 * corner_radius and width > 2 * corner_radius:
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("scrollbar_oval_3_a", "scrollbar_corner_part", "scrollbar_parts"), anchor=tkinter.CENTER)
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("scrollbar_oval_3_b", "scrollbar_corner_part", "scrollbar_parts"), anchor=tkinter.CENTER, angle=180)
|
||||||
|
requires_recoloring = True
|
||||||
|
elif self._canvas.find_withtag("scrollbar_oval_3_a") and not (height > 2 * corner_radius and width > 2 * corner_radius):
|
||||||
|
self._canvas.delete("scrollbar_oval_3_a", "scrollbar_oval_3_b")
|
||||||
|
|
||||||
|
if not self._canvas.find_withtag("scrollbar_oval_4_a") and height > 2 * corner_radius:
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("scrollbar_oval_4_a", "scrollbar_corner_part", "scrollbar_parts"), anchor=tkinter.CENTER)
|
||||||
|
self._canvas.create_aa_circle(0, 0, 0, tags=("scrollbar_oval_4_b", "scrollbar_corner_part", "scrollbar_parts"), anchor=tkinter.CENTER, angle=180)
|
||||||
|
requires_recoloring = True
|
||||||
|
elif self._canvas.find_withtag("scrollbar_oval_4_a") and not height > 2 * corner_radius:
|
||||||
|
self._canvas.delete("scrollbar_oval_4_a", "scrollbar_oval_4_b")
|
||||||
|
else:
|
||||||
|
self._canvas.delete("scrollbar_corner_part")
|
||||||
|
|
||||||
|
if not self._canvas.find_withtag("scrollbar_rectangle_1") and height > 2 * corner_radius:
|
||||||
|
self._canvas.create_rectangle(0, 0, 0, 0, tags=("scrollbar_rectangle_1", "scrollbar_rectangle_part", "scrollbar_parts"), width=0)
|
||||||
|
requires_recoloring = True
|
||||||
|
elif self._canvas.find_withtag("scrollbar_rectangle_1") and not height > 2 * corner_radius:
|
||||||
|
self._canvas.delete("scrollbar_rectangle_1")
|
||||||
|
|
||||||
|
if not self._canvas.find_withtag("scrollbar_rectangle_2") and width > 2 * corner_radius:
|
||||||
|
self._canvas.create_rectangle(0, 0, 0, 0, tags=("scrollbar_rectangle_2", "scrollbar_rectangle_part", "scrollbar_parts"), width=0)
|
||||||
|
requires_recoloring = True
|
||||||
|
elif self._canvas.find_withtag("scrollbar_rectangle_2") and not width > 2 * corner_radius:
|
||||||
|
self._canvas.delete("scrollbar_rectangle_2")
|
||||||
|
|
||||||
|
if orientation == "vertical":
|
||||||
|
self._canvas.coords("scrollbar_rectangle_1",
|
||||||
|
corner_radius - inner_corner_radius, corner_radius + (height - 2 * corner_radius) * start_value,
|
||||||
|
width - (corner_radius - inner_corner_radius), corner_radius + (height - 2 * corner_radius) * end_value)
|
||||||
|
self._canvas.coords("scrollbar_rectangle_2",
|
||||||
|
corner_radius, corner_radius - inner_corner_radius + (height - 2 * corner_radius) * start_value,
|
||||||
|
width - (corner_radius), corner_radius + inner_corner_radius + (height - 2 * corner_radius) * end_value)
|
||||||
|
|
||||||
|
self._canvas.coords("scrollbar_oval_1_a", corner_radius, corner_radius + (height - 2 * corner_radius) * start_value, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_1_b", corner_radius, corner_radius + (height - 2 * corner_radius) * start_value, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_2_a", width - corner_radius, corner_radius + (height - 2 * corner_radius) * start_value, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_2_b", width - corner_radius, corner_radius + (height - 2 * corner_radius) * start_value, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_3_a", width - corner_radius, corner_radius + (height - 2 * corner_radius) * end_value, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_3_b", width - corner_radius, corner_radius + (height - 2 * corner_radius) * end_value, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_4_a", corner_radius, corner_radius + (height - 2 * corner_radius) * end_value, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_4_b", corner_radius, corner_radius + (height - 2 * corner_radius) * end_value, inner_corner_radius)
|
||||||
|
|
||||||
|
if orientation == "horizontal":
|
||||||
|
self._canvas.coords("scrollbar_rectangle_1",
|
||||||
|
corner_radius - inner_corner_radius + (width - 2 * corner_radius) * start_value, corner_radius,
|
||||||
|
corner_radius + inner_corner_radius + (width - 2 * corner_radius) * end_value, height - corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_rectangle_2",
|
||||||
|
corner_radius + (width - 2 * corner_radius) * start_value, corner_radius - inner_corner_radius,
|
||||||
|
corner_radius + (width - 2 * corner_radius) * end_value, height - (corner_radius - inner_corner_radius))
|
||||||
|
|
||||||
|
self._canvas.coords("scrollbar_oval_1_a", corner_radius + (width - 2 * corner_radius) * start_value, corner_radius, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_1_b", corner_radius + (width - 2 * corner_radius) * start_value, corner_radius, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_2_a", corner_radius + (width - 2 * corner_radius) * end_value, corner_radius, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_2_b", corner_radius + (width - 2 * corner_radius) * end_value, corner_radius, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_3_a", corner_radius + (width - 2 * corner_radius) * end_value, height - corner_radius, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_3_b", corner_radius + (width - 2 * corner_radius) * end_value, height - corner_radius, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_4_a", corner_radius + (width - 2 * corner_radius) * start_value, height - corner_radius, inner_corner_radius)
|
||||||
|
self._canvas.coords("scrollbar_oval_4_b", corner_radius + (width - 2 * corner_radius) * start_value, height - corner_radius, inner_corner_radius)
|
||||||
|
|
||||||
|
return requires_recoloring
|
||||||
|
|
||||||
def draw_checkmark(self, width: Union[float, int], height: Union[float, int], size: Union[int, float]) -> bool:
|
def draw_checkmark(self, width: Union[float, int], height: Union[float, 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,
|
""" 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.
|
the main foreground elements have an 'inner_parts' tag to color the elements accordingly.
|
||||||
|
@ -3,3 +3,4 @@ class Settings:
|
|||||||
cursor_manipulation_enabled = True
|
cursor_manipulation_enabled = True
|
||||||
deactivate_macos_window_header_manipulation = False
|
deactivate_macos_window_header_manipulation = False
|
||||||
deactivate_windows_window_header_manipulation = False
|
deactivate_windows_window_header_manipulation = False
|
||||||
|
use_dropdown_fallback = True
|
||||||
|
@ -29,12 +29,19 @@ class CTkCanvas(tkinter.Canvas):
|
|||||||
9: 'E', 8: 'F', 7: 'C', 6: 'I', 5: 'E', 4: 'G', 3: 'P', 2: 'R', 1: 'R',
|
9: 'E', 8: 'F', 7: 'C', 6: 'I', 5: 'E', 4: 'G', 3: 'P', 2: 'R', 1: 'R',
|
||||||
0: 'A'}
|
0: 'A'}
|
||||||
|
|
||||||
|
radius_to_char_fine_linux = {19: 'A', 18: 'A', 17: 'B', 16: 'B', 15: 'B', 14: 'B', 13: 'F', 12: 'C',
|
||||||
|
11: 'F', 10: 'C',
|
||||||
|
9: 'D', 8: 'G', 7: 'D', 6: 'F', 5: 'D', 4: 'G', 3: 'M', 2: 'H', 1: 'H',
|
||||||
|
0: 'A'}
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
if sys.getwindowsversion().build > 20000: # Windows 11
|
if sys.getwindowsversion().build > 20000: # Windows 11
|
||||||
cls.radius_to_char_fine = radius_to_char_fine_windows_11
|
cls.radius_to_char_fine = radius_to_char_fine_windows_11
|
||||||
else: # < Windows 11
|
else: # < Windows 11
|
||||||
cls.radius_to_char_fine = radius_to_char_fine_windows_10
|
cls.radius_to_char_fine = radius_to_char_fine_windows_10
|
||||||
else: # macOS and Linux
|
elif sys.platform.startswith("linux"): # Optimized on Kali Linux
|
||||||
|
cls.radius_to_char_fine = radius_to_char_fine_linux
|
||||||
|
else:
|
||||||
cls.radius_to_char_fine = radius_to_char_fine_windows_10
|
cls.radius_to_char_fine = radius_to_char_fine_windows_10
|
||||||
|
|
||||||
def get_char_from_radius(self, radius: int) -> str:
|
def get_char_from_radius(self, radius: int) -> str:
|
||||||
|
@ -12,7 +12,6 @@ from .widget_base_class import CTkBaseClass
|
|||||||
|
|
||||||
|
|
||||||
class CTkComboBox(CTkBaseClass):
|
class CTkComboBox(CTkBaseClass):
|
||||||
|
|
||||||
def __init__(self, *args,
|
def __init__(self, *args,
|
||||||
bg_color=None,
|
bg_color=None,
|
||||||
fg_color="default_theme",
|
fg_color="default_theme",
|
||||||
@ -30,6 +29,7 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
corner_radius="default_theme",
|
corner_radius="default_theme",
|
||||||
border_width="default_theme",
|
border_width="default_theme",
|
||||||
text_font="default_theme",
|
text_font="default_theme",
|
||||||
|
dropdown_text_font="default_theme",
|
||||||
text_color="default_theme",
|
text_color="default_theme",
|
||||||
text_color_disabled="default_theme",
|
text_color_disabled="default_theme",
|
||||||
hover=True,
|
hover=True,
|
||||||
@ -44,16 +44,12 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
self.border_color = ThemeManager.theme["color"]["combobox_border"] if border_color == "default_theme" else border_color
|
self.border_color = ThemeManager.theme["color"]["combobox_border"] if border_color == "default_theme" else border_color
|
||||||
self.button_color = ThemeManager.theme["color"]["combobox_border"] if button_color == "default_theme" else button_color
|
self.button_color = ThemeManager.theme["color"]["combobox_border"] if button_color == "default_theme" else button_color
|
||||||
self.button_hover_color = ThemeManager.theme["color"]["combobox_button_hover"] if button_hover_color == "default_theme" else button_hover_color
|
self.button_hover_color = ThemeManager.theme["color"]["combobox_button_hover"] if button_hover_color == "default_theme" else button_hover_color
|
||||||
self.dropdown_color = ThemeManager.theme["color"]["dropdown_color"] if dropdown_color == "default_theme" else dropdown_color
|
|
||||||
self.dropdown_hover_color = ThemeManager.theme["color"]["dropdown_hover"] if dropdown_hover_color == "default_theme" else dropdown_hover_color
|
|
||||||
self.dropdown_text_color = ThemeManager.theme["color"]["dropdown_text"] if dropdown_text_color == "default_theme" else dropdown_text_color
|
|
||||||
|
|
||||||
# shape
|
# shape
|
||||||
self.corner_radius = ThemeManager.theme["shape"]["button_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
self.corner_radius = ThemeManager.theme["shape"]["button_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
||||||
self.border_width = ThemeManager.theme["shape"]["entry_border_width"] if border_width == "default_theme" else border_width
|
self.border_width = ThemeManager.theme["shape"]["entry_border_width"] if border_width == "default_theme" else border_width
|
||||||
|
|
||||||
# text and font
|
# text and font
|
||||||
self.text_label = None
|
|
||||||
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
||||||
self.text_color_disabled = ThemeManager.theme["color"]["text_button_disabled"] if text_color_disabled == "default_theme" else text_color_disabled
|
self.text_color_disabled = ThemeManager.theme["color"]["text_button_disabled"] if text_color_disabled == "default_theme" else text_color_disabled
|
||||||
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||||
@ -63,7 +59,6 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
self.variable = variable
|
self.variable = variable
|
||||||
self.state = state
|
self.state = state
|
||||||
self.hover = hover
|
self.hover = hover
|
||||||
self.click_animation_running = False
|
|
||||||
|
|
||||||
if values is None:
|
if values is None:
|
||||||
self.values = ["CTkComboBox"]
|
self.values = ["CTkComboBox"]
|
||||||
@ -75,7 +70,13 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
else:
|
else:
|
||||||
self.current_value = "CTkComboBox"
|
self.current_value = "CTkComboBox"
|
||||||
|
|
||||||
self.dropdown_menu: Union[DropdownMenu, None] = None
|
self.dropdown_menu = DropdownMenu(master=self,
|
||||||
|
values=self.values,
|
||||||
|
command=self.set,
|
||||||
|
fg_color=dropdown_color,
|
||||||
|
hover_color=dropdown_hover_color,
|
||||||
|
text_color=dropdown_text_color,
|
||||||
|
text_font=dropdown_text_font)
|
||||||
|
|
||||||
# configure grid system (1x1)
|
# configure grid system (1x1)
|
||||||
self.grid_rowconfigure(0, weight=1)
|
self.grid_rowconfigure(0, weight=1)
|
||||||
@ -96,8 +97,11 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
font=self.apply_font_scaling(self.text_font))
|
font=self.apply_font_scaling(self.text_font))
|
||||||
left_section_width = self._current_width - self._current_height
|
left_section_width = self._current_width - self._current_height
|
||||||
self.entry.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="ew",
|
self.entry.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="ew",
|
||||||
padx=(self.apply_widget_scaling(max(self.corner_radius, 3)),
|
padx=(max(self.apply_widget_scaling(self.corner_radius), self.apply_widget_scaling(3)),
|
||||||
self.apply_widget_scaling(max(self._current_width - left_section_width + 3, 3))))
|
max(self.apply_widget_scaling(self._current_width - left_section_width + 3), self.apply_widget_scaling(3))))
|
||||||
|
|
||||||
|
self.entry.delete(0, tkinter.END)
|
||||||
|
self.entry.insert(0, self.current_value)
|
||||||
|
|
||||||
self.draw() # initial draw
|
self.draw() # initial draw
|
||||||
|
|
||||||
@ -139,10 +143,6 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
self.apply_widget_scaling(self._current_height / 2),
|
self.apply_widget_scaling(self._current_height / 2),
|
||||||
self.apply_widget_scaling(self._current_height / 3))
|
self.apply_widget_scaling(self._current_height / 3))
|
||||||
|
|
||||||
if self.current_value is not None:
|
|
||||||
self.entry.delete(0, tkinter.END)
|
|
||||||
self.entry.insert(0, self.current_value)
|
|
||||||
|
|
||||||
if no_color_updates is False or requires_recoloring or requires_recoloring_2:
|
if no_color_updates is False or requires_recoloring or requires_recoloring_2:
|
||||||
|
|
||||||
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||||
@ -160,28 +160,21 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
outline=ThemeManager.single_color(self.border_color, self._appearance_mode),
|
outline=ThemeManager.single_color(self.border_color, self._appearance_mode),
|
||||||
fill=ThemeManager.single_color(self.border_color, self._appearance_mode))
|
fill=ThemeManager.single_color(self.border_color, self._appearance_mode))
|
||||||
|
|
||||||
self.entry.configure(fg=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
self.entry.configure(bg=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
||||||
self.entry.configure(bg=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
fg=ThemeManager.single_color(self.text_color, self._appearance_mode),
|
||||||
|
disabledforeground=ThemeManager.single_color(self.text_color_disabled, self._appearance_mode),
|
||||||
|
disabledbackground=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
||||||
|
|
||||||
if self.state == tkinter.DISABLED:
|
if self.state == tkinter.DISABLED:
|
||||||
self.entry.configure(fg=(ThemeManager.single_color(self.text_color_disabled, self._appearance_mode)))
|
|
||||||
self.canvas.itemconfig("dropdown_arrow",
|
self.canvas.itemconfig("dropdown_arrow",
|
||||||
fill=ThemeManager.single_color(self.text_color_disabled, self._appearance_mode))
|
fill=ThemeManager.single_color(self.text_color_disabled, self._appearance_mode))
|
||||||
else:
|
else:
|
||||||
self.entry.configure(fg=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
|
||||||
self.canvas.itemconfig("dropdown_arrow",
|
self.canvas.itemconfig("dropdown_arrow",
|
||||||
fill=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
fill=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
||||||
|
|
||||||
def open_dropdown_menu(self):
|
def open_dropdown_menu(self):
|
||||||
self.dropdown_menu = DropdownMenu(x_position=self.winfo_rootx(),
|
self.dropdown_menu.open(self.winfo_rootx(),
|
||||||
y_position=self.winfo_rooty() + self.apply_widget_scaling(self._current_height + 4),
|
self.winfo_rooty() + self.apply_widget_scaling(self._current_height + 0))
|
||||||
width=self._current_width,
|
|
||||||
values=self.values,
|
|
||||||
command=self.set,
|
|
||||||
fg_color=self.dropdown_color,
|
|
||||||
button_hover_color=self.dropdown_hover_color,
|
|
||||||
button_color=self.dropdown_color,
|
|
||||||
text_color=self.dropdown_text_color)
|
|
||||||
|
|
||||||
def configure(self, *args, **kwargs):
|
def configure(self, *args, **kwargs):
|
||||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||||
@ -240,6 +233,23 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
if "values" in kwargs:
|
if "values" in kwargs:
|
||||||
self.values = kwargs["values"]
|
self.values = kwargs["values"]
|
||||||
del kwargs["values"]
|
del kwargs["values"]
|
||||||
|
self.dropdown_menu.configure(values=self.values)
|
||||||
|
|
||||||
|
if "dropdown_color" in kwargs:
|
||||||
|
self.dropdown_menu.configure(fg_color=kwargs["dropdown_color"])
|
||||||
|
del kwargs["dropdown_color"]
|
||||||
|
|
||||||
|
if "dropdown_hover_color" in kwargs:
|
||||||
|
self.dropdown_menu.configure(hover_color=kwargs["dropdown_hover_color"])
|
||||||
|
del kwargs["dropdown_hover_color"]
|
||||||
|
|
||||||
|
if "dropdown_text_color" in kwargs:
|
||||||
|
self.dropdown_menu.configure(text_color=kwargs["dropdown_text_color"])
|
||||||
|
del kwargs["dropdown_text_color"]
|
||||||
|
|
||||||
|
if "dropdown_text_font" in kwargs:
|
||||||
|
self.dropdown_menu.configure(text_font=kwargs["dropdown_text_font"])
|
||||||
|
del kwargs["dropdown_text_font"]
|
||||||
|
|
||||||
super().configure(*args, **kwargs)
|
super().configure(*args, **kwargs)
|
||||||
|
|
||||||
@ -262,8 +272,6 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
fill=ThemeManager.single_color(self.button_hover_color, self._appearance_mode))
|
fill=ThemeManager.single_color(self.button_hover_color, self._appearance_mode))
|
||||||
|
|
||||||
def on_leave(self, event=0):
|
def on_leave(self, event=0):
|
||||||
self.click_animation_running = False
|
|
||||||
|
|
||||||
if self.hover is True:
|
if self.hover is True:
|
||||||
if sys.platform == "darwin" and len(self.values) > 0 and Settings.cursor_manipulation_enabled:
|
if sys.platform == "darwin" and len(self.values) > 0 and Settings.cursor_manipulation_enabled:
|
||||||
self.canvas.configure(cursor="arrow")
|
self.canvas.configure(cursor="arrow")
|
||||||
@ -278,10 +286,6 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
outline=ThemeManager.single_color(self.button_color, self._appearance_mode),
|
outline=ThemeManager.single_color(self.button_color, self._appearance_mode),
|
||||||
fill=ThemeManager.single_color(self.button_color, self._appearance_mode))
|
fill=ThemeManager.single_color(self.button_color, self._appearance_mode))
|
||||||
|
|
||||||
def click_animation(self):
|
|
||||||
if self.click_animation_running:
|
|
||||||
self.on_enter()
|
|
||||||
|
|
||||||
def set(self, value: str, from_variable_callback: bool = False):
|
def set(self, value: str, from_variable_callback: bool = False):
|
||||||
self.current_value = value
|
self.current_value = value
|
||||||
|
|
||||||
@ -298,8 +302,3 @@ class CTkComboBox(CTkBaseClass):
|
|||||||
def clicked(self, event=0):
|
def clicked(self, event=0):
|
||||||
if self.state is not tkinter.DISABLED and len(self.values) > 0:
|
if self.state is not tkinter.DISABLED and len(self.values) > 0:
|
||||||
self.open_dropdown_menu()
|
self.open_dropdown_menu()
|
||||||
|
|
||||||
# click animation: change color with .on_leave() and back to normal after 100ms with click_animation()
|
|
||||||
self.on_leave()
|
|
||||||
self.click_animation_running = True
|
|
||||||
self.after(100, self.click_animation)
|
|
||||||
|
@ -51,7 +51,7 @@ class CTkEntry(CTkBaseClass):
|
|||||||
highlightthickness=0,
|
highlightthickness=0,
|
||||||
width=self.apply_widget_scaling(self._current_width),
|
width=self.apply_widget_scaling(self._current_width),
|
||||||
height=self.apply_widget_scaling(self._current_height))
|
height=self.apply_widget_scaling(self._current_height))
|
||||||
self.canvas.grid(column=0, row=0, sticky="we")
|
self.canvas.grid(column=0, row=0, sticky="nswe")
|
||||||
self.draw_engine = DrawEngine(self.canvas)
|
self.draw_engine = DrawEngine(self.canvas)
|
||||||
|
|
||||||
self.entry = tkinter.Entry(master=self,
|
self.entry = tkinter.Entry(master=self,
|
||||||
@ -61,8 +61,9 @@ class CTkEntry(CTkBaseClass):
|
|||||||
font=self.apply_font_scaling(self.text_font),
|
font=self.apply_font_scaling(self.text_font),
|
||||||
state=self.state,
|
state=self.state,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
self.entry.grid(column=0, row=0, sticky="we",
|
self.entry.grid(column=0, row=0, sticky="nswe",
|
||||||
padx=self.apply_widget_scaling(self.corner_radius) if self.corner_radius >= 6 else self.apply_widget_scaling(6))
|
padx=self.apply_widget_scaling(self.corner_radius) if self.corner_radius >= 6 else self.apply_widget_scaling(6),
|
||||||
|
pady=(self.apply_widget_scaling(self.border_width), self.apply_widget_scaling(self.border_width + 1)))
|
||||||
|
|
||||||
super().bind('<Configure>', self.update_dimensions_event)
|
super().bind('<Configure>', self.update_dimensions_event)
|
||||||
self.entry.bind('<FocusOut>', self.set_placeholder)
|
self.entry.bind('<FocusOut>', self.set_placeholder)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import tkinter
|
import tkinter
|
||||||
import sys
|
import sys
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from .dropdown_menu import DropdownMenu
|
from .dropdown_menu import DropdownMenu
|
||||||
|
|
||||||
@ -12,12 +11,13 @@ from .widget_base_class import CTkBaseClass
|
|||||||
|
|
||||||
|
|
||||||
class CTkOptionMenu(CTkBaseClass):
|
class CTkOptionMenu(CTkBaseClass):
|
||||||
|
|
||||||
def __init__(self, *args,
|
def __init__(self, *args,
|
||||||
bg_color=None,
|
bg_color=None,
|
||||||
fg_color="default_theme",
|
fg_color="default_theme",
|
||||||
button_color="default_theme",
|
button_color="default_theme",
|
||||||
button_hover_color="default_theme",
|
button_hover_color="default_theme",
|
||||||
|
text_color="default_theme",
|
||||||
|
text_color_disabled="default_theme",
|
||||||
dropdown_color="default_theme",
|
dropdown_color="default_theme",
|
||||||
dropdown_hover_color="default_theme",
|
dropdown_hover_color="default_theme",
|
||||||
dropdown_text_color="default_theme",
|
dropdown_text_color="default_theme",
|
||||||
@ -28,10 +28,10 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
height=28,
|
height=28,
|
||||||
corner_radius="default_theme",
|
corner_radius="default_theme",
|
||||||
text_font="default_theme",
|
text_font="default_theme",
|
||||||
text_color="default_theme",
|
dropdown_text_font="default_theme",
|
||||||
text_color_disabled="default_theme",
|
|
||||||
hover=True,
|
hover=True,
|
||||||
state=tkinter.NORMAL,
|
state=tkinter.NORMAL,
|
||||||
|
dynamic_resizing=True,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
|
||||||
# transfer basic functionality (bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
# transfer basic functionality (bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
||||||
@ -41,18 +41,15 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
self.fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
self.fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
||||||
self.button_color = ThemeManager.theme["color"]["optionmenu_button"] if button_color == "default_theme" else button_color
|
self.button_color = ThemeManager.theme["color"]["optionmenu_button"] if button_color == "default_theme" else button_color
|
||||||
self.button_hover_color = ThemeManager.theme["color"]["optionmenu_button_hover"] if button_hover_color == "default_theme" else button_hover_color
|
self.button_hover_color = ThemeManager.theme["color"]["optionmenu_button_hover"] if button_hover_color == "default_theme" else button_hover_color
|
||||||
self.dropdown_color = ThemeManager.theme["color"]["dropdown_color"] if dropdown_color == "default_theme" else dropdown_color
|
|
||||||
self.dropdown_hover_color = ThemeManager.theme["color"]["dropdown_hover"] if dropdown_hover_color == "default_theme" else dropdown_hover_color
|
|
||||||
self.dropdown_text_color = ThemeManager.theme["color"]["dropdown_text"] if dropdown_text_color == "default_theme" else dropdown_text_color
|
|
||||||
|
|
||||||
# shape
|
# shape
|
||||||
self.corner_radius = ThemeManager.theme["shape"]["button_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
self.corner_radius = ThemeManager.theme["shape"]["button_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
||||||
|
|
||||||
# text and font
|
# text and font
|
||||||
self.text_label = None
|
|
||||||
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
||||||
self.text_color_disabled = ThemeManager.theme["color"]["text_button_disabled"] if text_color_disabled == "default_theme" else text_color_disabled
|
self.text_color_disabled = ThemeManager.theme["color"]["text_button_disabled"] if text_color_disabled == "default_theme" else text_color_disabled
|
||||||
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||||
|
self.dropdown_text_font = dropdown_text_font
|
||||||
|
|
||||||
# callback and hover functionality
|
# callback and hover functionality
|
||||||
self.function = command
|
self.function = command
|
||||||
@ -61,7 +58,7 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
self.variable_callback_name = None
|
self.variable_callback_name = None
|
||||||
self.state = state
|
self.state = state
|
||||||
self.hover = hover
|
self.hover = hover
|
||||||
self.click_animation_running = False
|
self.dynamic_resizing = dynamic_resizing
|
||||||
|
|
||||||
if values is None:
|
if values is None:
|
||||||
self.values = ["CTkOptionMenu"]
|
self.values = ["CTkOptionMenu"]
|
||||||
@ -73,7 +70,13 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
else:
|
else:
|
||||||
self.current_value = "CTkOptionMenu"
|
self.current_value = "CTkOptionMenu"
|
||||||
|
|
||||||
self.dropdown_menu: Union[DropdownMenu, None] = None
|
self.dropdown_menu = DropdownMenu(master=self,
|
||||||
|
values=self.values,
|
||||||
|
command=self.set,
|
||||||
|
fg_color=dropdown_color,
|
||||||
|
hover_color=dropdown_hover_color,
|
||||||
|
text_color=dropdown_text_color,
|
||||||
|
text_font=dropdown_text_font)
|
||||||
|
|
||||||
# configure grid system (1x1)
|
# configure grid system (1x1)
|
||||||
self.grid_rowconfigure(0, weight=1)
|
self.grid_rowconfigure(0, weight=1)
|
||||||
@ -86,11 +89,32 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
self.canvas.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="nsew")
|
self.canvas.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="nsew")
|
||||||
self.draw_engine = DrawEngine(self.canvas)
|
self.draw_engine = DrawEngine(self.canvas)
|
||||||
|
|
||||||
|
left_section_width = self._current_width - self._current_height
|
||||||
|
self.text_label = tkinter.Label(master=self, font=self.apply_font_scaling(self.text_font), anchor="w")
|
||||||
|
self.text_label.grid(row=0, column=0, sticky="w",
|
||||||
|
padx=(max(self.apply_widget_scaling(self.corner_radius), self.apply_widget_scaling(3)),
|
||||||
|
max(self.apply_widget_scaling(self._current_width - left_section_width + 3), self.apply_widget_scaling(3))))
|
||||||
|
|
||||||
|
if not self.dynamic_resizing:
|
||||||
|
self.grid_propagate(0)
|
||||||
|
|
||||||
|
if Settings.cursor_manipulation_enabled:
|
||||||
|
if sys.platform == "darwin":
|
||||||
|
self.configure(cursor="pointinghand")
|
||||||
|
elif sys.platform.startswith("win"):
|
||||||
|
self.configure(cursor="hand2")
|
||||||
|
|
||||||
# event bindings
|
# event bindings
|
||||||
self.canvas.bind("<Enter>", self.on_enter)
|
self.canvas.bind("<Enter>", self.on_enter)
|
||||||
self.canvas.bind("<Leave>", self.on_leave)
|
self.canvas.bind("<Leave>", self.on_leave)
|
||||||
self.canvas.bind("<Button-1>", self.clicked)
|
self.canvas.bind("<Button-1>", self.clicked)
|
||||||
self.canvas.bind("<Button-1>", self.clicked)
|
self.canvas.bind("<Button-1>", self.clicked)
|
||||||
|
|
||||||
|
self.text_label.bind("<Enter>", self.on_enter)
|
||||||
|
self.text_label.bind("<Leave>", self.on_leave)
|
||||||
|
self.text_label.bind("<Button-1>", self.clicked)
|
||||||
|
self.text_label.bind("<Button-1>", self.clicked)
|
||||||
|
|
||||||
self.bind('<Configure>', self.update_dimensions_event)
|
self.bind('<Configure>', self.update_dimensions_event)
|
||||||
|
|
||||||
self.draw() # initial draw
|
self.draw() # initial draw
|
||||||
@ -128,17 +152,6 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
requires_recoloring_2 = self.draw_engine.draw_dropdown_arrow(self.apply_widget_scaling(self._current_width - (self._current_height / 2)),
|
requires_recoloring_2 = self.draw_engine.draw_dropdown_arrow(self.apply_widget_scaling(self._current_width - (self._current_height / 2)),
|
||||||
self.apply_widget_scaling(self._current_height / 2),
|
self.apply_widget_scaling(self._current_height / 2),
|
||||||
self.apply_widget_scaling(self._current_height / 3))
|
self.apply_widget_scaling(self._current_height / 3))
|
||||||
if self.text_label is None:
|
|
||||||
self.text_label = tkinter.Label(master=self,
|
|
||||||
font=self.apply_font_scaling(self.text_font))
|
|
||||||
self.text_label.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="w",
|
|
||||||
padx=(max(self.apply_widget_scaling(self.corner_radius), 3),
|
|
||||||
max(self._current_width - left_section_width + 3, 3)))
|
|
||||||
|
|
||||||
self.text_label.bind("<Enter>", self.on_enter)
|
|
||||||
self.text_label.bind("<Leave>", self.on_leave)
|
|
||||||
self.text_label.bind("<Button-1>", self.clicked)
|
|
||||||
self.text_label.bind("<Button-1>", self.clicked)
|
|
||||||
|
|
||||||
if self.current_value is not None:
|
if self.current_value is not None:
|
||||||
self.text_label.configure(text=self.current_value)
|
self.text_label.configure(text=self.current_value)
|
||||||
@ -167,62 +180,51 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
|
|
||||||
self.text_label.configure(bg=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
self.text_label.configure(bg=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
||||||
|
|
||||||
|
self.canvas.update_idletasks()
|
||||||
|
|
||||||
def open_dropdown_menu(self):
|
def open_dropdown_menu(self):
|
||||||
self.dropdown_menu = DropdownMenu(x_position=self.winfo_rootx(),
|
self.dropdown_menu.open(self.winfo_rootx(),
|
||||||
y_position=self.winfo_rooty() + self.apply_widget_scaling(self._current_height + 4),
|
self.winfo_rooty() + self.apply_widget_scaling(self._current_height + 0))
|
||||||
width=self._current_width,
|
|
||||||
values=self.values,
|
|
||||||
command=self.set,
|
|
||||||
fg_color=self.dropdown_color,
|
|
||||||
button_hover_color=self.dropdown_hover_color,
|
|
||||||
button_color=self.dropdown_color,
|
|
||||||
text_color=self.dropdown_text_color)
|
|
||||||
|
|
||||||
def configure(self, *args, **kwargs):
|
def configure(self, *args, **kwargs):
|
||||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||||
|
|
||||||
if "state" in kwargs:
|
if "state" in kwargs:
|
||||||
self.state = kwargs["state"]
|
self.state = kwargs.pop("state")
|
||||||
require_redraw = True
|
require_redraw = True
|
||||||
del kwargs["state"]
|
|
||||||
|
|
||||||
if "fg_color" in kwargs:
|
if "fg_color" in kwargs:
|
||||||
self.fg_color = kwargs["fg_color"]
|
self.fg_color = kwargs.pop("fg_color")
|
||||||
require_redraw = True
|
require_redraw = True
|
||||||
del kwargs["fg_color"]
|
|
||||||
|
|
||||||
if "bg_color" in kwargs:
|
if "bg_color" in kwargs:
|
||||||
if kwargs["bg_color"] is None:
|
new_bg_color = kwargs.pop("bg_color")
|
||||||
|
if new_bg_color is None:
|
||||||
self.bg_color = self.detect_color_of_master()
|
self.bg_color = self.detect_color_of_master()
|
||||||
else:
|
else:
|
||||||
self.bg_color = kwargs["bg_color"]
|
self.bg_color = new_bg_color
|
||||||
require_redraw = True
|
require_redraw = True
|
||||||
del kwargs["bg_color"]
|
|
||||||
|
|
||||||
if "button_color" in kwargs:
|
if "button_color" in kwargs:
|
||||||
self.button_color = kwargs["button_color"]
|
self.button_color = kwargs.pop("button_color")
|
||||||
require_redraw = True
|
require_redraw = True
|
||||||
del kwargs["button_color"]
|
|
||||||
|
|
||||||
if "button_hover_color" in kwargs:
|
if "button_hover_color" in kwargs:
|
||||||
self.button_hover_color = kwargs["button_hover_color"]
|
self.button_hover_color = kwargs.pop("button_hover_color")
|
||||||
require_redraw = True
|
require_redraw = True
|
||||||
del kwargs["button_hover_color"]
|
|
||||||
|
|
||||||
if "text_color" in kwargs:
|
if "text_color" in kwargs:
|
||||||
self.text_color = kwargs["text_color"]
|
self.text_color = kwargs.pop("text_color")
|
||||||
require_redraw = True
|
require_redraw = True
|
||||||
del kwargs["text_color"]
|
|
||||||
|
|
||||||
if "command" in kwargs:
|
if "command" in kwargs:
|
||||||
self.function = kwargs["command"]
|
self.function = kwargs.pop("command")
|
||||||
del kwargs["command"]
|
|
||||||
|
|
||||||
if "variable" in kwargs:
|
if "variable" in kwargs:
|
||||||
if self.variable is not None: # remove old callback
|
if self.variable is not None: # remove old callback
|
||||||
self.variable.trace_remove("write", self.variable_callback_name)
|
self.variable.trace_remove("write", self.variable_callback_name)
|
||||||
|
|
||||||
self.variable = kwargs["variable"]
|
self.variable = kwargs.pop("variable")
|
||||||
|
|
||||||
if self.variable is not None and self.variable != "":
|
if self.variable is not None and self.variable != "":
|
||||||
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
||||||
@ -230,19 +232,34 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
else:
|
else:
|
||||||
self.variable = None
|
self.variable = None
|
||||||
|
|
||||||
del kwargs["variable"]
|
|
||||||
|
|
||||||
if "width" in kwargs:
|
if "width" in kwargs:
|
||||||
self.set_dimensions(width=kwargs["width"])
|
self.set_dimensions(width=kwargs.pop("width"))
|
||||||
del kwargs["width"]
|
|
||||||
|
|
||||||
if "height" in kwargs:
|
if "height" in kwargs:
|
||||||
self.set_dimensions(height=kwargs["height"])
|
self.set_dimensions(height=kwargs.pop("height"))
|
||||||
del kwargs["height"]
|
|
||||||
|
|
||||||
if "values" in kwargs:
|
if "values" in kwargs:
|
||||||
self.values = kwargs["values"]
|
self.values = kwargs.pop("values")
|
||||||
del kwargs["values"]
|
self.dropdown_menu.configure(values=self.values)
|
||||||
|
|
||||||
|
if "dropdown_color" in kwargs:
|
||||||
|
self.dropdown_menu.configure(fg_color=kwargs.pop("dropdown_color"))
|
||||||
|
|
||||||
|
if "dropdown_hover_color" in kwargs:
|
||||||
|
self.dropdown_menu.configure(hover_color=kwargs.pop("dropdown_hover_color"))
|
||||||
|
|
||||||
|
if "dropdown_text_color" in kwargs:
|
||||||
|
self.dropdown_menu.configure(text_color=kwargs.pop("dropdown_text_color"))
|
||||||
|
|
||||||
|
if "dropdown_text_font" in kwargs:
|
||||||
|
self.dropdown_menu.configure(text_font=kwargs.pop("dropdown_text_font"))
|
||||||
|
|
||||||
|
if "dynamic_resizing" in kwargs:
|
||||||
|
self.dynamic_resizing = kwargs.pop("dynamic_resizing")
|
||||||
|
if not self.dynamic_resizing:
|
||||||
|
self.grid_propagate(0)
|
||||||
|
else:
|
||||||
|
self.grid_propagate(1)
|
||||||
|
|
||||||
super().configure(*args, **kwargs)
|
super().configure(*args, **kwargs)
|
||||||
|
|
||||||
@ -251,34 +268,18 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
|
|
||||||
def on_enter(self, event=0):
|
def on_enter(self, event=0):
|
||||||
if self.hover is True and self.state == tkinter.NORMAL and len(self.values) > 0:
|
if self.hover is True and self.state == tkinter.NORMAL and len(self.values) > 0:
|
||||||
if sys.platform == "darwin" and len(self.values) > 0 and Settings.cursor_manipulation_enabled:
|
|
||||||
self.configure(cursor="pointinghand")
|
|
||||||
elif sys.platform.startswith("win") and len(self.values) > 0 and Settings.cursor_manipulation_enabled:
|
|
||||||
self.configure(cursor="hand2")
|
|
||||||
|
|
||||||
# set color of inner button parts to hover color
|
# set color of inner button parts to hover color
|
||||||
self.canvas.itemconfig("inner_parts_right",
|
self.canvas.itemconfig("inner_parts_right",
|
||||||
outline=ThemeManager.single_color(self.button_hover_color, self._appearance_mode),
|
outline=ThemeManager.single_color(self.button_hover_color, self._appearance_mode),
|
||||||
fill=ThemeManager.single_color(self.button_hover_color, self._appearance_mode))
|
fill=ThemeManager.single_color(self.button_hover_color, self._appearance_mode))
|
||||||
|
|
||||||
def on_leave(self, event=0):
|
def on_leave(self, event=0):
|
||||||
self.click_animation_running = False
|
|
||||||
|
|
||||||
if self.hover is True:
|
if self.hover is True:
|
||||||
if sys.platform == "darwin" and len(self.values) > 0 and Settings.cursor_manipulation_enabled:
|
|
||||||
self.configure(cursor="arrow")
|
|
||||||
elif sys.platform.startswith("win") and len(self.values) > 0 and Settings.cursor_manipulation_enabled:
|
|
||||||
self.configure(cursor="arrow")
|
|
||||||
|
|
||||||
# set color of inner button parts
|
# set color of inner button parts
|
||||||
self.canvas.itemconfig("inner_parts_right",
|
self.canvas.itemconfig("inner_parts_right",
|
||||||
outline=ThemeManager.single_color(self.button_color, self._appearance_mode),
|
outline=ThemeManager.single_color(self.button_color, self._appearance_mode),
|
||||||
fill=ThemeManager.single_color(self.button_color, self._appearance_mode))
|
fill=ThemeManager.single_color(self.button_color, self._appearance_mode))
|
||||||
|
|
||||||
def click_animation(self):
|
|
||||||
if self.click_animation_running:
|
|
||||||
self.on_enter()
|
|
||||||
|
|
||||||
def variable_callback(self, var_name, index, mode):
|
def variable_callback(self, var_name, index, mode):
|
||||||
if not self.variable_callback_blocked:
|
if not self.variable_callback_blocked:
|
||||||
self.set(self.variable.get(), from_variable_callback=True)
|
self.set(self.variable.get(), from_variable_callback=True)
|
||||||
@ -306,8 +307,3 @@ class CTkOptionMenu(CTkBaseClass):
|
|||||||
def clicked(self, event=0):
|
def clicked(self, event=0):
|
||||||
if self.state is not tkinter.DISABLED and len(self.values) > 0:
|
if self.state is not tkinter.DISABLED and len(self.values) > 0:
|
||||||
self.open_dropdown_menu()
|
self.open_dropdown_menu()
|
||||||
|
|
||||||
# click animation: change color with .on_leave() and back to normal after 100ms with click_animation()
|
|
||||||
self.on_leave()
|
|
||||||
self.click_animation_running = True
|
|
||||||
self.after(100, self.click_animation)
|
|
||||||
|
238
customtkinter/widgets/ctk_scrollbar.py
Normal file
238
customtkinter/widgets/ctk_scrollbar.py
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from .ctk_canvas import CTkCanvas
|
||||||
|
from ..theme_manager import ThemeManager
|
||||||
|
from ..draw_engine import DrawEngine
|
||||||
|
from .widget_base_class import CTkBaseClass
|
||||||
|
|
||||||
|
|
||||||
|
class CTkScrollbar(CTkBaseClass):
|
||||||
|
def __init__(self, *args,
|
||||||
|
bg_color=None,
|
||||||
|
fg_color="default_theme",
|
||||||
|
scrollbar_color="default_theme",
|
||||||
|
scrollbar_hover_color="default_theme",
|
||||||
|
border_spacing="default_theme",
|
||||||
|
corner_radius="default_theme",
|
||||||
|
width=None,
|
||||||
|
height=None,
|
||||||
|
minimum_pixel_length=20,
|
||||||
|
orientation="vertical",
|
||||||
|
command=None,
|
||||||
|
hover=True,
|
||||||
|
**kwargs):
|
||||||
|
|
||||||
|
# set default dimensions according to orientation
|
||||||
|
if width is None:
|
||||||
|
if orientation.lower() == "vertical":
|
||||||
|
width = 16
|
||||||
|
else:
|
||||||
|
width = 200
|
||||||
|
if height is None:
|
||||||
|
if orientation.lower() == "horizontal":
|
||||||
|
height = 16
|
||||||
|
else:
|
||||||
|
height = 200
|
||||||
|
|
||||||
|
# transfer basic functionality (bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
||||||
|
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs)
|
||||||
|
|
||||||
|
# color
|
||||||
|
self.fg_color = ThemeManager.theme["color"]["frame_high"] if fg_color == "default_theme" else fg_color
|
||||||
|
self.scrollbar_color = ThemeManager.theme["color"]["scrollbar_button"] if scrollbar_color == "default_theme" else scrollbar_color
|
||||||
|
self.scrollbar_hover_color = ThemeManager.theme["color"]["scrollbar_button_hover"] if scrollbar_hover_color == "default_theme" else scrollbar_hover_color
|
||||||
|
|
||||||
|
# shape
|
||||||
|
self.corner_radius = ThemeManager.theme["shape"]["scrollbar_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
||||||
|
self.border_spacing = ThemeManager.theme["shape"]["scrollbar_border_spacing"] if border_spacing == "default_theme" else border_spacing
|
||||||
|
|
||||||
|
self.hover = hover
|
||||||
|
self.hover_state = False
|
||||||
|
self.command = command
|
||||||
|
self.orientation = orientation
|
||||||
|
self.start_value: float = 0 # 0 to 1
|
||||||
|
self.end_value: float = 1 # 0 to 1
|
||||||
|
self.minimum_pixel_length = minimum_pixel_length
|
||||||
|
|
||||||
|
self.canvas = CTkCanvas(master=self,
|
||||||
|
highlightthickness=0,
|
||||||
|
width=self.apply_widget_scaling(self._current_width),
|
||||||
|
height=self.apply_widget_scaling(self._current_height))
|
||||||
|
self.canvas.place(x=0, y=0, relwidth=1, relheight=1)
|
||||||
|
self.draw_engine = DrawEngine(self.canvas)
|
||||||
|
|
||||||
|
self.canvas.bind("<Enter>", self.on_enter)
|
||||||
|
self.canvas.bind("<Leave>", self.on_leave)
|
||||||
|
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)
|
||||||
|
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def set_scaling(self, *args, **kwargs):
|
||||||
|
super().set_scaling(*args, **kwargs)
|
||||||
|
|
||||||
|
self.canvas.configure(width=self.apply_widget_scaling(self._desired_width), height=self.apply_widget_scaling(self._desired_height))
|
||||||
|
self.draw(no_color_updates=True)
|
||||||
|
|
||||||
|
def set_dimensions(self, width=None, height=None):
|
||||||
|
super().set_dimensions(width, height)
|
||||||
|
|
||||||
|
self.canvas.configure(width=self.apply_widget_scaling(self._desired_width),
|
||||||
|
height=self.apply_widget_scaling(self._desired_height))
|
||||||
|
self.draw(no_color_updates=True)
|
||||||
|
|
||||||
|
def get_scrollbar_values_for_minimum_pixel_size(self):
|
||||||
|
# correct scrollbar float values if scrollbar is too small
|
||||||
|
if self.orientation == "vertical":
|
||||||
|
scrollbar_pixel_length = (self.end_value - self.start_value) * self._current_height
|
||||||
|
if scrollbar_pixel_length < self.minimum_pixel_length and -scrollbar_pixel_length + self._current_height != 0:
|
||||||
|
# calculate how much to increase the float interval values so that the scrollbar width is self.minimum_pixel_length
|
||||||
|
interval_extend_factor = (-scrollbar_pixel_length + self.minimum_pixel_length) / (-scrollbar_pixel_length + self._current_height)
|
||||||
|
corrected_end_value = self.end_value + (1 - self.end_value) * interval_extend_factor
|
||||||
|
corrected_start_value = self.start_value - self.start_value * interval_extend_factor
|
||||||
|
return corrected_start_value, corrected_end_value
|
||||||
|
else:
|
||||||
|
return self.start_value, self.end_value
|
||||||
|
|
||||||
|
else:
|
||||||
|
scrollbar_pixel_length = (self.end_value - self.start_value) * self._current_width
|
||||||
|
if scrollbar_pixel_length < self.minimum_pixel_length and -scrollbar_pixel_length + self._current_width != 0:
|
||||||
|
# calculate how much to increase the float interval values so that the scrollbar width is self.minimum_pixel_length
|
||||||
|
interval_extend_factor = (-scrollbar_pixel_length + self.minimum_pixel_length) / (-scrollbar_pixel_length + self._current_width)
|
||||||
|
corrected_end_value = self.end_value + (1 - self.end_value) * interval_extend_factor
|
||||||
|
corrected_start_value = self.start_value - self.start_value * interval_extend_factor
|
||||||
|
return corrected_start_value, corrected_end_value
|
||||||
|
else:
|
||||||
|
return self.start_value, self.end_value
|
||||||
|
|
||||||
|
def draw(self, no_color_updates=False):
|
||||||
|
corrected_start_value, corrected_end_value = self.get_scrollbar_values_for_minimum_pixel_size()
|
||||||
|
requires_recoloring = self.draw_engine.draw_rounded_scrollbar(self.apply_widget_scaling(self._current_width),
|
||||||
|
self.apply_widget_scaling(self._current_height),
|
||||||
|
self.apply_widget_scaling(self.corner_radius),
|
||||||
|
self.apply_widget_scaling(self.border_spacing),
|
||||||
|
corrected_start_value,
|
||||||
|
corrected_end_value,
|
||||||
|
self.orientation)
|
||||||
|
|
||||||
|
if no_color_updates is False or requires_recoloring:
|
||||||
|
if self.hover_state is True:
|
||||||
|
self.canvas.itemconfig("scrollbar_parts",
|
||||||
|
fill=ThemeManager.single_color(self.scrollbar_hover_color, self._appearance_mode),
|
||||||
|
outline=ThemeManager.single_color(self.scrollbar_hover_color, self._appearance_mode))
|
||||||
|
else:
|
||||||
|
self.canvas.itemconfig("scrollbar_parts",
|
||||||
|
fill=ThemeManager.single_color(self.scrollbar_color, self._appearance_mode),
|
||||||
|
outline=ThemeManager.single_color(self.scrollbar_color, self._appearance_mode))
|
||||||
|
|
||||||
|
if self.fg_color is None:
|
||||||
|
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||||
|
self.canvas.itemconfig("border_parts",
|
||||||
|
fill=ThemeManager.single_color(self.bg_color, self._appearance_mode),
|
||||||
|
outline=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||||
|
else:
|
||||||
|
self.canvas.configure(bg=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
||||||
|
self.canvas.itemconfig("border_parts",
|
||||||
|
fill=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
||||||
|
outline=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
||||||
|
|
||||||
|
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 configure(self, *args, **kwargs):
|
||||||
|
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||||
|
|
||||||
|
if "bg_color" in kwargs:
|
||||||
|
if kwargs["bg_color"] is None:
|
||||||
|
self.bg_color = self.detect_color_of_master()
|
||||||
|
else:
|
||||||
|
self.bg_color = kwargs["bg_color"]
|
||||||
|
require_redraw = True
|
||||||
|
del kwargs["bg_color"]
|
||||||
|
|
||||||
|
if "fg_color" in kwargs:
|
||||||
|
self.fg_color = kwargs["fg_color"]
|
||||||
|
require_redraw = True
|
||||||
|
del kwargs["fg_color"]
|
||||||
|
|
||||||
|
if "scrollbar_color" in kwargs:
|
||||||
|
self.scrollbar_color = kwargs["scrollbar_color"]
|
||||||
|
require_redraw = True
|
||||||
|
del kwargs["scrollbar_color"]
|
||||||
|
|
||||||
|
if "scrollbar_hover_color" in kwargs:
|
||||||
|
self.scrollbar_hover_color = kwargs["scrollbar_hover_color"]
|
||||||
|
require_redraw = True
|
||||||
|
del kwargs["scrollbar_hover_color"]
|
||||||
|
|
||||||
|
if "command" in kwargs:
|
||||||
|
self.command = kwargs["command"]
|
||||||
|
del kwargs["command"]
|
||||||
|
|
||||||
|
if "corner_radius" in kwargs:
|
||||||
|
self.corner_radius = kwargs["corner_radius"]
|
||||||
|
require_redraw = True
|
||||||
|
del kwargs["corner_radius"]
|
||||||
|
|
||||||
|
if "border_spacing" in kwargs:
|
||||||
|
self.border_spacing = kwargs["border_spacing"]
|
||||||
|
require_redraw = True
|
||||||
|
del kwargs["border_spacing"]
|
||||||
|
|
||||||
|
if "width" in kwargs:
|
||||||
|
self.set_dimensions(width=kwargs["width"])
|
||||||
|
del kwargs["width"]
|
||||||
|
|
||||||
|
if "height" in kwargs:
|
||||||
|
self.set_dimensions(height=kwargs["height"])
|
||||||
|
del kwargs["height"]
|
||||||
|
|
||||||
|
super().configure(*args, **kwargs)
|
||||||
|
|
||||||
|
if require_redraw:
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def on_enter(self, event=0):
|
||||||
|
if self.hover is True:
|
||||||
|
self.hover_state = True
|
||||||
|
self.canvas.itemconfig("scrollbar_parts",
|
||||||
|
outline=ThemeManager.single_color(self.scrollbar_hover_color, self._appearance_mode),
|
||||||
|
fill=ThemeManager.single_color(self.scrollbar_hover_color, self._appearance_mode))
|
||||||
|
|
||||||
|
def on_leave(self, event=0):
|
||||||
|
self.hover_state = False
|
||||||
|
self.canvas.itemconfig("scrollbar_parts",
|
||||||
|
outline=ThemeManager.single_color(self.scrollbar_color, self._appearance_mode),
|
||||||
|
fill=ThemeManager.single_color(self.scrollbar_color, self._appearance_mode))
|
||||||
|
|
||||||
|
def clicked(self, event):
|
||||||
|
if self.orientation == "vertical":
|
||||||
|
value = ((event.y - self.border_spacing) / (self._current_height - 2 * self.border_spacing)) / self._widget_scaling
|
||||||
|
else:
|
||||||
|
value = ((event.x - self.border_spacing) / (self._current_width - 2 * self.border_spacing)) / self._widget_scaling
|
||||||
|
|
||||||
|
current_scrollbar_length = self.end_value - self.start_value
|
||||||
|
value = max(current_scrollbar_length / 2, min(value, 1 - (current_scrollbar_length / 2)))
|
||||||
|
self.start_value = value - (current_scrollbar_length / 2)
|
||||||
|
self.end_value = value + (current_scrollbar_length / 2)
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
if self.command is not None:
|
||||||
|
self.command('moveto', self.start_value)
|
||||||
|
|
||||||
|
def mouse_scroll_event(self, event=None):
|
||||||
|
if self.command is not None:
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
self.command('scroll', -int(event.delta/40), 'units')
|
||||||
|
else:
|
||||||
|
self.command('scroll', -event.delta, 'units')
|
||||||
|
|
@ -30,6 +30,7 @@ class CTkSlider(CTkBaseClass):
|
|||||||
command=None,
|
command=None,
|
||||||
variable=None,
|
variable=None,
|
||||||
orient="horizontal",
|
orient="horizontal",
|
||||||
|
state="normal",
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
|
||||||
# set default dimensions according to orientation
|
# set default dimensions according to orientation
|
||||||
@ -60,7 +61,7 @@ class CTkSlider(CTkBaseClass):
|
|||||||
self.border_width = ThemeManager.theme["shape"]["slider_border_width"] if border_width == "default_theme" else border_width
|
self.border_width = ThemeManager.theme["shape"]["slider_border_width"] if border_width == "default_theme" else border_width
|
||||||
self.button_length = ThemeManager.theme["shape"]["slider_button_length"] if button_length == "default_theme" else button_length
|
self.button_length = ThemeManager.theme["shape"]["slider_button_length"] if button_length == "default_theme" else button_length
|
||||||
self.value = 0.5 # initial value of slider in percent
|
self.value = 0.5 # initial value of slider in percent
|
||||||
self.orient = orient
|
self.orientation = orient
|
||||||
self.hover_state = False
|
self.hover_state = False
|
||||||
self.from_ = from_
|
self.from_ = from_
|
||||||
self.to = to
|
self.to = to
|
||||||
@ -75,6 +76,7 @@ class CTkSlider(CTkBaseClass):
|
|||||||
self.variable: tkinter.Variable = variable
|
self.variable: tkinter.Variable = variable
|
||||||
self.variable_callback_blocked = False
|
self.variable_callback_blocked = False
|
||||||
self.variable_callback_name = None
|
self.variable_callback_name = None
|
||||||
|
self.state = state
|
||||||
|
|
||||||
self.grid_rowconfigure(0, weight=1)
|
self.grid_rowconfigure(0, weight=1)
|
||||||
self.grid_columnconfigure(0, weight=1)
|
self.grid_columnconfigure(0, weight=1)
|
||||||
@ -124,16 +126,22 @@ class CTkSlider(CTkBaseClass):
|
|||||||
super().destroy()
|
super().destroy()
|
||||||
|
|
||||||
def set_cursor(self):
|
def set_cursor(self):
|
||||||
if Settings.cursor_manipulation_enabled:
|
if self.state == "normal" and Settings.cursor_manipulation_enabled:
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
self.configure(cursor="pointinghand")
|
self.configure(cursor="pointinghand")
|
||||||
elif sys.platform.startswith("win"):
|
elif sys.platform.startswith("win"):
|
||||||
self.configure(cursor="hand2")
|
self.configure(cursor="hand2")
|
||||||
|
|
||||||
|
elif self.state == "disabled" and Settings.cursor_manipulation_enabled:
|
||||||
|
if sys.platform == "darwin":
|
||||||
|
self.configure(cursor="arrow")
|
||||||
|
elif sys.platform.startswith("win"):
|
||||||
|
self.configure(cursor="arrow")
|
||||||
|
|
||||||
def draw(self, no_color_updates=False):
|
def draw(self, no_color_updates=False):
|
||||||
if self.orient.lower() == "horizontal":
|
if self.orientation.lower() == "horizontal":
|
||||||
orientation = "w"
|
orientation = "w"
|
||||||
elif self.orient.lower() == "vertical":
|
elif self.orientation.lower() == "vertical":
|
||||||
orientation = "s"
|
orientation = "s"
|
||||||
else:
|
else:
|
||||||
orientation = "w"
|
orientation = "w"
|
||||||
@ -166,11 +174,18 @@ class CTkSlider(CTkBaseClass):
|
|||||||
self.canvas.itemconfig("progress_parts", fill=ThemeManager.single_color(self.progress_color, self._appearance_mode),
|
self.canvas.itemconfig("progress_parts", fill=ThemeManager.single_color(self.progress_color, self._appearance_mode),
|
||||||
outline=ThemeManager.single_color(self.progress_color, self._appearance_mode))
|
outline=ThemeManager.single_color(self.progress_color, self._appearance_mode))
|
||||||
|
|
||||||
self.canvas.itemconfig("slider_parts", fill=ThemeManager.single_color(self.button_color, self._appearance_mode),
|
if self.hover_state is True:
|
||||||
|
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))
|
||||||
|
else:
|
||||||
|
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))
|
outline=ThemeManager.single_color(self.button_color, self._appearance_mode))
|
||||||
|
|
||||||
def clicked(self, event=None):
|
def clicked(self, event=None):
|
||||||
if self.orient.lower() == "horizontal":
|
if self.state == "normal":
|
||||||
|
if self.orientation.lower() == "horizontal":
|
||||||
self.value = (event.x / self._current_width) / self._widget_scaling
|
self.value = (event.x / self._current_width) / self._widget_scaling
|
||||||
else:
|
else:
|
||||||
self.value = 1 - (event.y / self._current_height) / self._widget_scaling
|
self.value = 1 - (event.y / self._current_height) / self._widget_scaling
|
||||||
@ -185,22 +200,25 @@ class CTkSlider(CTkBaseClass):
|
|||||||
|
|
||||||
self.draw(no_color_updates=False)
|
self.draw(no_color_updates=False)
|
||||||
|
|
||||||
if self.callback_function is not None:
|
|
||||||
self.callback_function(self.output_value)
|
|
||||||
|
|
||||||
if self.variable is not None:
|
if self.variable is not None:
|
||||||
self.variable_callback_blocked = True
|
self.variable_callback_blocked = True
|
||||||
self.variable.set(round(self.output_value) if isinstance(self.variable, tkinter.IntVar) else self.output_value)
|
self.variable.set(round(self.output_value) if isinstance(self.variable, tkinter.IntVar) else self.output_value)
|
||||||
self.variable_callback_blocked = False
|
self.variable_callback_blocked = False
|
||||||
|
|
||||||
|
if self.callback_function is not None:
|
||||||
|
self.callback_function(self.output_value)
|
||||||
|
|
||||||
def on_enter(self, event=0):
|
def on_enter(self, event=0):
|
||||||
|
if self.state == "normal":
|
||||||
self.hover_state = True
|
self.hover_state = True
|
||||||
self.canvas.itemconfig("slider_parts", fill=ThemeManager.single_color(self.button_hover_color, self._appearance_mode),
|
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))
|
outline=ThemeManager.single_color(self.button_hover_color, self._appearance_mode))
|
||||||
|
|
||||||
def on_leave(self, event=0):
|
def on_leave(self, event=0):
|
||||||
self.hover_state = False
|
self.hover_state = False
|
||||||
self.canvas.itemconfig("slider_parts", fill=ThemeManager.single_color(self.button_color, self._appearance_mode),
|
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))
|
outline=ThemeManager.single_color(self.button_color, self._appearance_mode))
|
||||||
|
|
||||||
def round_to_step_size(self, value):
|
def round_to_step_size(self, value):
|
||||||
@ -231,8 +249,8 @@ class CTkSlider(CTkBaseClass):
|
|||||||
|
|
||||||
self.draw(no_color_updates=False)
|
self.draw(no_color_updates=False)
|
||||||
|
|
||||||
if self.callback_function is not None:
|
# if self.callback_function is not None and not from_variable_callback:
|
||||||
self.callback_function(self.output_value)
|
# self.callback_function(self.output_value)
|
||||||
|
|
||||||
if self.variable is not None and not from_variable_callback:
|
if self.variable is not None and not from_variable_callback:
|
||||||
self.variable_callback_blocked = True
|
self.variable_callback_blocked = True
|
||||||
@ -246,6 +264,12 @@ class CTkSlider(CTkBaseClass):
|
|||||||
def configure(self, *args, **kwargs):
|
def configure(self, *args, **kwargs):
|
||||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||||
|
|
||||||
|
if "state" in kwargs:
|
||||||
|
self.state = kwargs["state"]
|
||||||
|
self.set_cursor()
|
||||||
|
require_redraw = True
|
||||||
|
del kwargs["state"]
|
||||||
|
|
||||||
if "fg_color" in kwargs:
|
if "fg_color" in kwargs:
|
||||||
self.fg_color = kwargs["fg_color"]
|
self.fg_color = kwargs["fg_color"]
|
||||||
require_redraw = True
|
require_redraw = True
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import customtkinter
|
|
||||||
import tkinter
|
import tkinter
|
||||||
import sys
|
import sys
|
||||||
|
import copy
|
||||||
|
import re
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
from ..theme_manager import ThemeManager
|
from ..theme_manager import ThemeManager
|
||||||
@ -8,20 +9,13 @@ from ..appearance_mode_tracker import AppearanceModeTracker
|
|||||||
from ..scaling_tracker import ScalingTracker
|
from ..scaling_tracker import ScalingTracker
|
||||||
|
|
||||||
|
|
||||||
class DropdownMenu(tkinter.Toplevel):
|
class DropdownMenu(tkinter.Menu):
|
||||||
def __init__(self, *args,
|
def __init__(self, *args,
|
||||||
fg_color="#555555",
|
min_character_width=18,
|
||||||
button_color="gray50",
|
fg_color="default_theme",
|
||||||
button_hover_color="gray35",
|
hover_color="default_theme",
|
||||||
text_color="black",
|
text_color="default_theme",
|
||||||
corner_radius=6,
|
text_font="default_theme",
|
||||||
button_corner_radius=3,
|
|
||||||
width=120,
|
|
||||||
button_height=24,
|
|
||||||
x_position=0,
|
|
||||||
y_position=0,
|
|
||||||
x_spacing=3,
|
|
||||||
y_spacing=3,
|
|
||||||
command=None,
|
command=None,
|
||||||
values=None,
|
values=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
@ -31,84 +25,105 @@ class DropdownMenu(tkinter.Toplevel):
|
|||||||
self._widget_scaling = ScalingTracker.get_widget_scaling(self)
|
self._widget_scaling = ScalingTracker.get_widget_scaling(self)
|
||||||
self._spacing_scaling = ScalingTracker.get_spacing_scaling(self)
|
self._spacing_scaling = ScalingTracker.get_spacing_scaling(self)
|
||||||
|
|
||||||
|
AppearanceModeTracker.add(self.set_appearance_mode, self)
|
||||||
|
self._appearance_mode = AppearanceModeTracker.get_mode() # 0: "Light" 1: "Dark"
|
||||||
|
|
||||||
|
self.min_character_width = min_character_width
|
||||||
|
self.fg_color = ThemeManager.theme["color"]["dropdown_color"] if fg_color == "default_theme" else fg_color
|
||||||
|
self.hover_color = ThemeManager.theme["color"]["dropdown_hover"] if hover_color == "default_theme" else hover_color
|
||||||
|
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
||||||
|
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||||
|
|
||||||
|
self.configure_menu_for_platforms()
|
||||||
|
|
||||||
self.values = values
|
self.values = values
|
||||||
self.command = command
|
self.command = command
|
||||||
|
|
||||||
# color
|
self.add_menu_commands()
|
||||||
self.appearance_mode = AppearanceModeTracker.get_mode() # 0: "Light" 1: "Dark"
|
|
||||||
self.fg_color = fg_color
|
|
||||||
self.button_color = button_color
|
|
||||||
self.button_hover_color = button_hover_color
|
|
||||||
self.text_color = text_color
|
|
||||||
|
|
||||||
# shape
|
def configure_menu_for_platforms(self):
|
||||||
self.corner_radius = corner_radius
|
if sys.platform == "darwin":
|
||||||
self.button_corner_radius = button_corner_radius
|
self.configure(tearoff=False,
|
||||||
self.button_height = button_height
|
font=self.apply_font_scaling(self.text_font))
|
||||||
self.width = width
|
|
||||||
self.height = max(len(self.values), 1) * (self.button_height + self.apply_spacing_scaling(y_spacing)) + self.apply_spacing_scaling(y_spacing)
|
|
||||||
|
|
||||||
self.geometry(f"{round(self.apply_widget_scaling(self.width))}x" +
|
|
||||||
f"{round(self.apply_widget_scaling(self.height))}+" +
|
|
||||||
f"{round(x_position)}+{round(y_position)}")
|
|
||||||
self.grid_columnconfigure(0, weight=1)
|
|
||||||
self.grid_rowconfigure(0, weight=1)
|
|
||||||
|
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
self.overrideredirect(True) # remove title-bar
|
|
||||||
self.overrideredirect(False)
|
|
||||||
self.wm_attributes("-transparent", True) # turn off window shadow
|
|
||||||
self.config(bg='systemTransparent') # transparent bg
|
|
||||||
self.frame = customtkinter.CTkFrame(self,
|
|
||||||
border_width=0,
|
|
||||||
width=self.width,
|
|
||||||
corner_radius=self.corner_radius,
|
|
||||||
fg_color=ThemeManager.single_color(self.fg_color, self.appearance_mode))
|
|
||||||
|
|
||||||
elif sys.platform.startswith("win"):
|
elif sys.platform.startswith("win"):
|
||||||
self.overrideredirect(True) # remove title-bar
|
self.configure(tearoff=False,
|
||||||
self.configure(bg="#010302")
|
relief="flat",
|
||||||
self.wm_attributes("-transparentcolor", "#010302")
|
activebackground=ThemeManager.single_color(self.hover_color, self._appearance_mode),
|
||||||
self.focus()
|
borderwidth=0,
|
||||||
self.frame = customtkinter.CTkFrame(self,
|
activeborderwidth=self.apply_widget_scaling(4),
|
||||||
border_width=0,
|
bg=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
||||||
width=self.width,
|
fg=ThemeManager.single_color(self.text_color, self._appearance_mode),
|
||||||
corner_radius=self.corner_radius,
|
activeforeground=ThemeManager.single_color(self.text_color, self._appearance_mode),
|
||||||
fg_color=self.fg_color, overwrite_preferred_drawing_method="circle_shapes")
|
font=self.apply_font_scaling(self.text_font),
|
||||||
|
cursor="hand2")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.overrideredirect(True) # remove title-bar
|
self.configure(tearoff=False,
|
||||||
self.configure(bg="#010302")
|
relief="flat",
|
||||||
self.wm_attributes("-transparentcolor", "#010302")
|
activebackground=ThemeManager.single_color(self.hover_color, self._appearance_mode),
|
||||||
self.frame = customtkinter.CTkFrame(self,
|
borderwidth=0,
|
||||||
border_width=0,
|
activeborderwidth=0,
|
||||||
width=self.width,
|
bg=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
||||||
corner_radius=self.corner_radius,
|
fg=ThemeManager.single_color(self.text_color, self._appearance_mode),
|
||||||
fg_color=self.fg_color, overwrite_preferred_drawing_method="circle_shapes")
|
activeforeground=ThemeManager.single_color(self.text_color, self._appearance_mode),
|
||||||
|
font=self.apply_font_scaling(self.text_font))
|
||||||
|
|
||||||
self.frame.grid(row=0, column=0, sticky="nsew", rowspan=1)
|
def add_menu_commands(self):
|
||||||
self.frame.grid_rowconfigure(len(self.values) + 1, minsize=self.apply_spacing_scaling(y_spacing)) # add spacing at the bottom
|
if sys.platform.startswith("linux"):
|
||||||
self.frame.grid_columnconfigure(0, weight=1)
|
for value in self.values:
|
||||||
|
self.add_command(label=" " + value.ljust(self.min_character_width) + " ",
|
||||||
|
command=lambda v=value: self.button_callback(v),
|
||||||
|
compound="left")
|
||||||
|
else:
|
||||||
|
for value in self.values:
|
||||||
|
self.add_command(label=value.ljust(self.min_character_width),
|
||||||
|
command=lambda v=value: self.button_callback(v),
|
||||||
|
compound="left")
|
||||||
|
|
||||||
self.button_list = []
|
def open(self, x: Union[int, float], y: Union[int, float]):
|
||||||
for index, option in enumerate(self.values):
|
if sys.platform == "darwin":
|
||||||
button = customtkinter.CTkButton(self.frame,
|
y += self.apply_widget_scaling(8)
|
||||||
text=option,
|
else:
|
||||||
height=self.button_height,
|
y += self.apply_widget_scaling(3)
|
||||||
width=self.width - 2 * self.apply_widget_scaling(x_spacing),
|
|
||||||
fg_color=self.button_color,
|
|
||||||
text_color=self.text_color,
|
|
||||||
hover_color=self.button_hover_color,
|
|
||||||
corner_radius=self.button_corner_radius,
|
|
||||||
command=lambda i=index: self.button_callback(i))
|
|
||||||
button.text_label.configure(anchor="w")
|
|
||||||
button.text_label.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="w")
|
|
||||||
button.grid(row=index, column=0,
|
|
||||||
padx=self.apply_widget_scaling(x_spacing),
|
|
||||||
pady=(self.apply_widget_scaling(y_spacing), 0), sticky="ew")
|
|
||||||
self.button_list.append(button)
|
|
||||||
|
|
||||||
self.bind("<FocusOut>", self.focus_loss_event)
|
if sys.platform == "darwin" or sys.platform.startswith("win"):
|
||||||
self.frame.canvas.bind("<Button-1>", self.focus_loss_event)
|
self.post(int(x), int(y))
|
||||||
|
else: # Linux
|
||||||
|
self.tk_popup(int(x), int(y))
|
||||||
|
|
||||||
|
def button_callback(self, value):
|
||||||
|
if self.command is not None:
|
||||||
|
self.command(value)
|
||||||
|
|
||||||
|
def configure(self, **kwargs):
|
||||||
|
if "values" in kwargs:
|
||||||
|
self.values = kwargs["values"]
|
||||||
|
del kwargs["values"]
|
||||||
|
self.delete(0, "end") # delete all old commands
|
||||||
|
self.add_menu_commands()
|
||||||
|
|
||||||
|
if "fg_color" in kwargs:
|
||||||
|
self.fg_color = kwargs["fg_color"]
|
||||||
|
del kwargs["fg_color"]
|
||||||
|
self.configure(bg=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
||||||
|
|
||||||
|
if "hover_color" in kwargs:
|
||||||
|
self.hover_color = kwargs["hover_color"]
|
||||||
|
del kwargs["hover_color"]
|
||||||
|
self.configure(activebackground=ThemeManager.single_color(self.hover_color, self._appearance_mode))
|
||||||
|
|
||||||
|
if "text_color" in kwargs:
|
||||||
|
self.text_color = kwargs["text_color"]
|
||||||
|
del kwargs["text_color"]
|
||||||
|
self.configure(fg=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
||||||
|
|
||||||
|
if "text_font" in kwargs:
|
||||||
|
self.text_font = kwargs["text_font"]
|
||||||
|
del kwargs["text_font"]
|
||||||
|
self.configure(font=self.apply_font_scaling(self.text_font))
|
||||||
|
|
||||||
|
super().configure(**kwargs)
|
||||||
|
|
||||||
def apply_widget_scaling(self, value: Union[int, float, str]) -> Union[float, str]:
|
def apply_widget_scaling(self, value: Union[int, float, str]) -> Union[float, str]:
|
||||||
if isinstance(value, (int, float)):
|
if isinstance(value, (int, float)):
|
||||||
@ -116,24 +131,43 @@ class DropdownMenu(tkinter.Toplevel):
|
|||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def apply_spacing_scaling(self, value: Union[int, float, str]) -> Union[float, str]:
|
def apply_font_scaling(self, font):
|
||||||
if isinstance(value, (int, float)):
|
if type(font) == tuple or type(font) == list:
|
||||||
return value * self._spacing_scaling
|
font_list = list(font)
|
||||||
|
for i in range(len(font_list)):
|
||||||
|
if (type(font_list[i]) == int or type(font_list[i]) == float) and font_list[i] < 0:
|
||||||
|
font_list[i] = int(font_list[i] * self._widget_scaling)
|
||||||
|
return tuple(font_list)
|
||||||
|
|
||||||
|
elif type(font) == str:
|
||||||
|
for negative_number in re.findall(r" -\d* ", font):
|
||||||
|
font = font.replace(negative_number, f" {int(int(negative_number) * self._widget_scaling)} ")
|
||||||
|
return font
|
||||||
|
|
||||||
|
elif isinstance(font, tkinter.font.Font):
|
||||||
|
new_font_object = copy.copy(font)
|
||||||
|
if font.cget("size") < 0:
|
||||||
|
new_font_object.config(size=int(font.cget("size") * self._widget_scaling))
|
||||||
|
return new_font_object
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return value
|
return font
|
||||||
|
|
||||||
def set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling):
|
def set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling):
|
||||||
return
|
self._widget_scaling = new_widget_scaling
|
||||||
|
self._spacing_scaling = new_spacing_scaling
|
||||||
|
|
||||||
def focus_loss_event(self, event):
|
self.configure(font=self.apply_font_scaling(self.text_font))
|
||||||
self.destroy()
|
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def button_callback(self, index):
|
if sys.platform.startswith("win"):
|
||||||
self.destroy()
|
self.configure(activeborderwidth=self.apply_widget_scaling(4))
|
||||||
if sys.platform.startswith("darwin"):
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
if self.command is not None:
|
def set_appearance_mode(self, mode_string):
|
||||||
self.command(self.values[index])
|
""" colors won't update on appearance mode change when dropdown is open, because it's not necessary """
|
||||||
|
|
||||||
|
if mode_string.lower() == "dark":
|
||||||
|
self._appearance_mode = 1
|
||||||
|
elif mode_string.lower() == "light":
|
||||||
|
self._appearance_mode = 0
|
||||||
|
|
||||||
|
self.configure_menu_for_platforms()
|
||||||
|
@ -46,30 +46,27 @@ class App(customtkinter.CTk):
|
|||||||
self.label_1.grid(row=1, column=0, pady=10, padx=10)
|
self.label_1.grid(row=1, column=0, pady=10, padx=10)
|
||||||
|
|
||||||
self.button_1 = customtkinter.CTkButton(master=self.frame_left,
|
self.button_1 = customtkinter.CTkButton(master=self.frame_left,
|
||||||
text="CTkButton 1",
|
text="CTkButton",
|
||||||
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
|
||||||
command=self.button_event)
|
command=self.button_event)
|
||||||
self.button_1.grid(row=2, column=0, pady=10, padx=20)
|
self.button_1.grid(row=2, column=0, pady=10, padx=20)
|
||||||
|
|
||||||
self.button_2 = customtkinter.CTkButton(master=self.frame_left,
|
self.button_2 = customtkinter.CTkButton(master=self.frame_left,
|
||||||
text="CTkButton 2",
|
text="CTkButton",
|
||||||
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
|
||||||
command=self.button_event)
|
command=self.button_event)
|
||||||
self.button_2.grid(row=3, column=0, pady=10, padx=20)
|
self.button_2.grid(row=3, column=0, pady=10, padx=20)
|
||||||
|
|
||||||
self.button_3 = customtkinter.CTkButton(master=self.frame_left,
|
self.button_3 = customtkinter.CTkButton(master=self.frame_left,
|
||||||
text="CTkButton 3",
|
text="CTkButton",
|
||||||
fg_color=("gray75", "gray30"), # <- custom tuple-color
|
|
||||||
command=self.button_event)
|
command=self.button_event)
|
||||||
self.button_3.grid(row=4, column=0, pady=10, padx=20)
|
self.button_3.grid(row=4, column=0, pady=10, padx=20)
|
||||||
|
|
||||||
self.switch_1 = customtkinter.CTkSwitch(master=self.frame_left)
|
self.label_mode = customtkinter.CTkLabel(master=self.frame_left, text="Appearance Mode:")
|
||||||
self.switch_1.grid(row=9, column=0, pady=10, padx=20, sticky="w")
|
self.label_mode.grid(row=9, column=0, pady=0, padx=20, sticky="w")
|
||||||
|
|
||||||
self.switch_2 = customtkinter.CTkSwitch(master=self.frame_left,
|
self.optionmenu_1 = customtkinter.CTkOptionMenu(master=self.frame_left,
|
||||||
text="Dark Mode",
|
values=["Light", "Dark", "System"],
|
||||||
command=self.change_mode)
|
command=self.change_appearance_mode)
|
||||||
self.switch_2.grid(row=10, column=0, pady=10, padx=20, sticky="w")
|
self.optionmenu_1.grid(row=10, column=0, pady=10, padx=20, sticky="w")
|
||||||
|
|
||||||
# ============ frame_right ============
|
# ============ frame_right ============
|
||||||
|
|
||||||
@ -134,25 +131,17 @@ class App(customtkinter.CTk):
|
|||||||
command=self.progressbar.set)
|
command=self.progressbar.set)
|
||||||
self.slider_2.grid(row=5, column=0, columnspan=2, pady=10, padx=20, sticky="we")
|
self.slider_2.grid(row=5, column=0, columnspan=2, pady=10, padx=20, sticky="we")
|
||||||
|
|
||||||
self.slider_button_1 = customtkinter.CTkButton(master=self.frame_right,
|
self.switch_1 = customtkinter.CTkSwitch(master=self.frame_right,
|
||||||
height=25,
|
text="CTkSwitch")
|
||||||
text="CTkButton",
|
self.switch_1.grid(row=4, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
||||||
command=self.button_event)
|
|
||||||
self.slider_button_1.grid(row=4, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
|
||||||
|
|
||||||
self.slider_button_2 = customtkinter.CTkButton(master=self.frame_right,
|
self.switch_2 = customtkinter.CTkSwitch(master=self.frame_right,
|
||||||
height=25,
|
text="CTkSwitch")
|
||||||
text="CTkButton",
|
self.switch_2.grid(row=5, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
||||||
command=self.button_event)
|
|
||||||
self.slider_button_2.grid(row=5, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
|
||||||
|
|
||||||
self.checkbox_button_1 = customtkinter.CTkButton(master=self.frame_right,
|
self.combobox_1 = customtkinter.CTkComboBox(master=self.frame_right,
|
||||||
height=25,
|
values=["Value 1", "Value 2"])
|
||||||
text="CTkButton",
|
self.combobox_1.grid(row=6, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
||||||
border_width=3, # <- custom border_width
|
|
||||||
fg_color=None, # <- no fg_color
|
|
||||||
command=self.button_event)
|
|
||||||
self.checkbox_button_1.grid(row=6, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
|
||||||
|
|
||||||
self.check_box_1 = customtkinter.CTkCheckBox(master=self.frame_right,
|
self.check_box_1 = customtkinter.CTkCheckBox(master=self.frame_right,
|
||||||
text="CTkCheckBox")
|
text="CTkCheckBox")
|
||||||
@ -169,16 +158,20 @@ class App(customtkinter.CTk):
|
|||||||
|
|
||||||
self.button_5 = customtkinter.CTkButton(master=self.frame_right,
|
self.button_5 = customtkinter.CTkButton(master=self.frame_right,
|
||||||
text="CTkButton",
|
text="CTkButton",
|
||||||
|
border_width=2, # <- custom border_width
|
||||||
|
fg_color=None, # <- no fg_color
|
||||||
command=self.button_event)
|
command=self.button_event)
|
||||||
self.button_5.grid(row=8, column=2, columnspan=1, pady=20, padx=20, sticky="we")
|
self.button_5.grid(row=8, column=2, columnspan=1, pady=20, padx=20, sticky="we")
|
||||||
|
|
||||||
# set default values
|
# set default values
|
||||||
|
self.optionmenu_1.set("Dark")
|
||||||
|
self.button_3.configure(state="disabled", text="Disabled CTkButton")
|
||||||
|
self.combobox_1.set("CTkCombobox")
|
||||||
self.radio_button_1.select()
|
self.radio_button_1.select()
|
||||||
self.switch_2.select()
|
|
||||||
self.slider_1.set(0.2)
|
self.slider_1.set(0.2)
|
||||||
self.slider_2.set(0.7)
|
self.slider_2.set(0.7)
|
||||||
self.progressbar.set(0.5)
|
self.progressbar.set(0.5)
|
||||||
self.slider_button_1.configure(state=tkinter.DISABLED, text="Disabled Button")
|
self.switch_2.select()
|
||||||
self.radio_button_3.configure(state=tkinter.DISABLED)
|
self.radio_button_3.configure(state=tkinter.DISABLED)
|
||||||
self.check_box_1.configure(state=tkinter.DISABLED, text="CheckBox disabled")
|
self.check_box_1.configure(state=tkinter.DISABLED, text="CheckBox disabled")
|
||||||
self.check_box_2.select()
|
self.check_box_2.select()
|
||||||
@ -186,11 +179,8 @@ class App(customtkinter.CTk):
|
|||||||
def button_event(self):
|
def button_event(self):
|
||||||
print("Button pressed")
|
print("Button pressed")
|
||||||
|
|
||||||
def change_mode(self):
|
def change_appearance_mode(self, new_appearance_mode):
|
||||||
if self.switch_2.get() == 1:
|
customtkinter.set_appearance_mode(new_appearance_mode)
|
||||||
customtkinter.set_appearance_mode("dark")
|
|
||||||
else:
|
|
||||||
customtkinter.set_appearance_mode("light")
|
|
||||||
|
|
||||||
def on_closing(self, event=0):
|
def on_closing(self, event=0):
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
@ -36,11 +36,11 @@ slider_1.set(0.5)
|
|||||||
entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
|
entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
|
||||||
entry_1.pack(pady=12, padx=10)
|
entry_1.pack(pady=12, padx=10)
|
||||||
|
|
||||||
optionmenu_1 = customtkinter.CTkOptionMenu(frame_1, values=["Option 1", "Option 2", "Option 42"])
|
optionmenu_1 = customtkinter.CTkOptionMenu(frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."])
|
||||||
optionmenu_1.pack(pady=12, padx=10)
|
optionmenu_1.pack(pady=12, padx=10)
|
||||||
optionmenu_1.set("CTkOptionMenu")
|
optionmenu_1.set("CTkOptionMenu")
|
||||||
|
|
||||||
combobox_1 = customtkinter.CTkComboBox(frame_1, values=["Option 1", "Option 2", "Option 42"])
|
combobox_1 = customtkinter.CTkComboBox(frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."])
|
||||||
combobox_1.pack(pady=12, padx=10)
|
combobox_1.pack(pady=12, padx=10)
|
||||||
optionmenu_1.set("CTkComboBox")
|
optionmenu_1.set("CTkComboBox")
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
github_url = "https://github.com/TomSchimansky/CustomTkinter"
|
github_url = "https://github.com/TomSchimansky/CustomTkinter"
|
||||||
|
|
||||||
[tool.tbump.version]
|
[tool.tbump.version]
|
||||||
current = "4.3.0"
|
current = "4.5.0"
|
||||||
|
|
||||||
# Example of a semver regexp.
|
# Example of a semver regexp.
|
||||||
# Make sure this matches current_version before
|
# Make sure this matches current_version before
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = customtkinter
|
name = customtkinter
|
||||||
version = 4.3.0
|
version = 4.5.0
|
||||||
description = Create modern looking GUIs with Python
|
description = Create modern looking GUIs with Python
|
||||||
long_description = '# CustomTkinter UI-Library\nhttps://github.com/TomSchimansky/CustomTkinter/blob/master/documentation_images/Windows_dark.png\n\nMore Information: https://github.com/TomSchimansky/CustomTkinter'
|
long_description = CustomTkinter UI-Library\n\n[](https://github.com/TomSchimansky/CustomTkinter/blob/master/documentation_images/Windows_dark.png)\n\nMore Information: https://github.com/TomSchimansky/CustomTkinter
|
||||||
long_description_content_type = text/markdown
|
long_description_content_type = text/markdown
|
||||||
url = https://github.com/TomSchimansky/CustomTkinter
|
url = https://github.com/TomSchimansky/CustomTkinter
|
||||||
author = Tom Schimansky
|
author = Tom Schimansky
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import tkinter
|
import tkinter
|
||||||
|
import tkinter.ttk as ttk
|
||||||
import customtkinter
|
import customtkinter
|
||||||
|
|
||||||
app = customtkinter.CTk()
|
app = customtkinter.CTk()
|
||||||
@ -11,21 +12,25 @@ def select_callback(choice):
|
|||||||
print("display_selected", choice)
|
print("display_selected", choice)
|
||||||
|
|
||||||
|
|
||||||
countries = ['Bahamas', 'Canada', 'Cuba', 'United States']
|
countries = ['Bahamas', 'Canada', 'Cuba', 'United States', "long sdhfhjgdshjafghdgshfhjdsfj"]
|
||||||
|
|
||||||
variable = tkinter.StringVar()
|
variable = tkinter.StringVar()
|
||||||
variable.set("test")
|
variable.set("test")
|
||||||
|
|
||||||
# optionmenu_tk = tkinter.OptionMenu(app, variable, *countries, command=select_callback)
|
optionmenu_tk = tkinter.OptionMenu(app, variable, *countries, command=select_callback)
|
||||||
# optionmenu_tk.pack(pady=10, padx=10)
|
optionmenu_tk.pack(pady=10, padx=10)
|
||||||
|
|
||||||
optionmenu_1 = customtkinter.CTkOptionMenu(app, variable=variable, values=countries, command=select_callback)
|
optionmenu_1 = customtkinter.CTkOptionMenu(app, variable=variable, values=countries, command=select_callback)
|
||||||
optionmenu_1.pack(pady=20, padx=10)
|
optionmenu_1.pack(pady=20, padx=10)
|
||||||
|
|
||||||
# combobox_tk = ttk.Combobox(app, values=countries)
|
optionmenu_2 = customtkinter.CTkOptionMenu(app, variable=variable, values=countries, command=select_callback,
|
||||||
# combobox_tk.pack(pady=10, padx=10)
|
dynamic_resizing=False)
|
||||||
|
optionmenu_2.pack(pady=20, padx=10)
|
||||||
|
|
||||||
combobox_1 = customtkinter.CTkComboBox(app, variable=variable, values=countries, command=select_callback)
|
combobox_tk = ttk.Combobox(app, values=countries)
|
||||||
|
combobox_tk.pack(pady=10, padx=10)
|
||||||
|
|
||||||
|
combobox_1 = customtkinter.CTkComboBox(app, variable=None, values=countries, command=select_callback, width=300)
|
||||||
combobox_1.pack(pady=20, padx=10)
|
combobox_1.pack(pady=20, padx=10)
|
||||||
|
|
||||||
app.mainloop()
|
app.mainloop()
|
||||||
|
54
test/manual_integration_tests/test_scrollbar.py
Normal file
54
test/manual_integration_tests/test_scrollbar.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import tkinter
|
||||||
|
import customtkinter
|
||||||
|
|
||||||
|
# test with scaling
|
||||||
|
# customtkinter.set_widget_scaling(2)
|
||||||
|
# customtkinter.set_window_scaling(2)
|
||||||
|
# customtkinter.set_spacing_scaling(2)
|
||||||
|
|
||||||
|
customtkinter.set_appearance_mode("dark")
|
||||||
|
|
||||||
|
app = customtkinter.CTk()
|
||||||
|
app.title("test_scrollbar.py")
|
||||||
|
app.grid_rowconfigure(0, weight=1)
|
||||||
|
app.grid_columnconfigure((0, 2), weight=1)
|
||||||
|
|
||||||
|
tk_textbox = tkinter.Text(app, highlightthickness=0, padx=5, pady=5)
|
||||||
|
tk_textbox.grid(row=0, column=0, sticky="nsew")
|
||||||
|
ctk_textbox_scrollbar = customtkinter.CTkScrollbar(app, command=tk_textbox.yview)
|
||||||
|
ctk_textbox_scrollbar.grid(row=0, column=1, padx=0, sticky="ns")
|
||||||
|
tk_textbox.configure(yscrollcommand=ctk_textbox_scrollbar.set)
|
||||||
|
|
||||||
|
frame_1 = customtkinter.CTkFrame(app)
|
||||||
|
frame_1.grid(row=0, column=2, padx=10, pady=10, sticky="nsew")
|
||||||
|
frame_1.grid_rowconfigure((0, 1), weight=1)
|
||||||
|
frame_1.grid_columnconfigure((0, ), weight=1)
|
||||||
|
tk_textbox_1 = tkinter.Text(frame_1, highlightthickness=0, padx=5, pady=5)
|
||||||
|
tk_textbox_1.grid(row=0, column=0, sticky="nsew", padx=(5, 0), pady=5)
|
||||||
|
ctk_textbox_scrollbar_1 = customtkinter.CTkScrollbar(frame_1, command=tk_textbox_1.yview)
|
||||||
|
ctk_textbox_scrollbar_1.grid(row=0, column=1, sticky="ns", padx=(0, 5), pady=5)
|
||||||
|
tk_textbox_1.configure(yscrollcommand=ctk_textbox_scrollbar_1.set)
|
||||||
|
ctk_textbox_scrollbar_1.configure(scrollbar_color="red", scrollbar_hover_color="darkred",
|
||||||
|
border_spacing=0, width=12, fg_color="green", corner_radius=4)
|
||||||
|
|
||||||
|
frame_2 = customtkinter.CTkFrame(frame_1)
|
||||||
|
frame_2.grid(row=1, column=0, columnspan=2, padx=20, pady=20, sticky="nsew")
|
||||||
|
frame_2.grid_rowconfigure((0, ), weight=1)
|
||||||
|
frame_2.grid_columnconfigure((0, ), weight=1)
|
||||||
|
tk_textbox_2 = tkinter.Text(frame_2, highlightthickness=0, padx=5, pady=5, wrap="none")
|
||||||
|
tk_textbox_2.grid(row=0, column=0, sticky="nsew", padx=(5, 0), pady=5)
|
||||||
|
ctk_textbox_scrollbar_2 = customtkinter.CTkScrollbar(frame_2, command=tk_textbox_2.yview)
|
||||||
|
ctk_textbox_scrollbar_2.grid(row=0, column=1, sticky="ns", padx=(0, 5), pady=5)
|
||||||
|
ctk_textbox_scrollbar_2_horizontal = customtkinter.CTkScrollbar(frame_2, command=tk_textbox_2.xview, orientation="horizontal")
|
||||||
|
ctk_textbox_scrollbar_2_horizontal.grid(row=1, column=0, sticky="ew", padx=(5, 0), pady=(0, 5))
|
||||||
|
tk_textbox_2.configure(yscrollcommand=ctk_textbox_scrollbar_2.set, xscrollcommand=ctk_textbox_scrollbar_2_horizontal.set)
|
||||||
|
|
||||||
|
tk_textbox.configure(font=(customtkinter.ThemeManager.theme["text"]["font"], customtkinter.ThemeManager.theme["text"]["size"]))
|
||||||
|
tk_textbox_1.configure(font=(customtkinter.ThemeManager.theme["text"]["font"], customtkinter.ThemeManager.theme["text"]["size"]))
|
||||||
|
tk_textbox_2.configure(font=(customtkinter.ThemeManager.theme["text"]["font"], customtkinter.ThemeManager.theme["text"]["size"]))
|
||||||
|
|
||||||
|
tk_textbox.insert("insert", "\n".join([str(i) for i in range(100)]))
|
||||||
|
tk_textbox_1.insert("insert", "\n".join([str(i) for i in range(1000)]))
|
||||||
|
tk_textbox_2.insert("insert", "\n".join([str(i) + " - "*30 for i in range(10000)]))
|
||||||
|
|
||||||
|
app.mainloop()
|
@ -3,7 +3,7 @@ import customtkinter
|
|||||||
|
|
||||||
|
|
||||||
app = customtkinter.CTk()
|
app = customtkinter.CTk()
|
||||||
app.geometry("400x800")
|
app.geometry("400x900")
|
||||||
app.title("CustomTkinter Test")
|
app.title("CustomTkinter Test")
|
||||||
|
|
||||||
|
|
||||||
@ -53,5 +53,10 @@ combobox_1.pack(pady=10, padx=10)
|
|||||||
button_7 = customtkinter.CTkButton(master=app, text="Disable/Enable combobox_1", command=lambda: change_state(combobox_1))
|
button_7 = customtkinter.CTkButton(master=app, text="Disable/Enable combobox_1", command=lambda: change_state(combobox_1))
|
||||||
button_7.pack(padx=20, pady=(10, 20))
|
button_7.pack(padx=20, pady=(10, 20))
|
||||||
|
|
||||||
|
slider_1 = customtkinter.CTkSlider(app)
|
||||||
|
slider_1.pack(pady=10, padx=10)
|
||||||
|
button_8 = customtkinter.CTkButton(master=app, text="Disable/Enable slider_1", command=lambda: change_state(slider_1))
|
||||||
|
button_8.pack(padx=20, pady=(10, 20))
|
||||||
|
|
||||||
|
|
||||||
app.mainloop()
|
app.mainloop()
|
Reference in New Issue
Block a user