Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented CtkSpinBox #2275

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions customtkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .windows.widgets import CTkScrollbar
from .windows.widgets import CTkSegmentedButton
from .windows.widgets import CTkSlider
from .windows.widgets import CTkSpinBox
from .windows.widgets import CTkSwitch
from .windows.widgets import CTkTabview
from .windows.widgets import CTkTextbox
Expand Down
10 changes: 10 additions & 0 deletions customtkinter/assets/themes/blue.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
"text_color": ["gray10", "#DCE4EE"],
"text_color_disabled": ["gray50", "gray45"]
},
"CTkSpinBox": {
"corner_radius": 6,
"border_width": 2,
"fg_color": ["#F9F9FA", "#343638"],
"border_color": ["#979DA2", "#565B5E"],
"button_color": ["#979DA2", "#565B5E"],
"button_hover_color": ["#6E7174", "#7A848D"],
"text_color": ["gray10", "#DCE4EE"],
"text_color_disabled": ["gray50", "gray45"]
},
"CTkScrollbar": {
"corner_radius": 1000,
"border_spacing": 4,
Expand Down
10 changes: 10 additions & 0 deletions customtkinter/assets/themes/dark-blue.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
"text_color": ["gray14", "gray84"],
"text_color_disabled": ["gray50", "gray45"]
},
"CTkSpinBox": {
"corner_radius": 6,
"border_width": 2,
"fg_color": ["#F9F9FA", "#343638"],
"border_color": ["#979DA2", "#565B5E"],
"button_color": ["#979DA2", "#565B5E"],
"button_hover_color": ["#6E7174", "#7A848D"],
"text_color": ["gray14", "gray84"],
"text_color_disabled": ["gray50", "gray45"]
},
"CTkScrollbar": {
"corner_radius": 1000,
"border_spacing": 4,
Expand Down
10 changes: 10 additions & 0 deletions customtkinter/assets/themes/green.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
"text_color": ["gray10", "#DCE4EE"],
"text_color_disabled": ["gray50", "gray45"]
},
"CTkSpinBox": {
"corner_radius": 6,
"border_width": 2,
"fg_color": ["#F9F9FA", "#343638"],
"border_color": ["#979DA2", "#565B5E"],
"button_color": ["#979DA2", "#565B5E"],
"button_hover_color": ["#6E7174", "#7A848D"],
"text_color": ["gray10", "#DCE4EE"],
"text_color_disabled": ["gray50", "gray45"]
},
"CTkScrollbar": {
"corner_radius": 1000,
"border_spacing": 4,
Expand Down
1 change: 1 addition & 0 deletions customtkinter/windows/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .ctk_scrollbar import CTkScrollbar
from .ctk_segmented_button import CTkSegmentedButton
from .ctk_slider import CTkSlider
from .ctk_spinbox import CTkSpinBox
from .ctk_switch import CTkSwitch
from .ctk_tabview import CTkTabview
from .ctk_textbox import CTkTextbox
Expand Down
42 changes: 25 additions & 17 deletions customtkinter/windows/widgets/core_rendering/draw_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import math
import tkinter
from typing import Union, TYPE_CHECKING
from typing import Union, Literal, TYPE_CHECKING

if TYPE_CHECKING:
from ..core_rendering import CTkCanvas
Expand All @@ -22,7 +22,7 @@ class DrawEngine:
- draw_rounded_slider_with_border_and_button()
- draw_rounded_scrollbar()
- draw_checkmark()
- draw_dropdown_arrow()
- draw_arrow()

"""

Expand Down Expand Up @@ -399,7 +399,7 @@ def __draw_rounded_rect_with_border_circle_shapes(self, width: int, height: int,
def draw_rounded_rect_with_border_vertical_split(self, width: Union[float, int], height: Union[float, int], corner_radius: Union[float, int],
border_width: Union[float, int], left_section_width: Union[float, int]) -> bool:
""" Draws a rounded rectangle with a corner_radius and border_width on the canvas which is split at left_section_width.
The border elements have the tags 'border_parts_left', 'border_parts_lright',
The border elements have the tags 'border_parts_left', 'border_parts_right',
the main foreground elements have an 'inner_parts_left' and inner_parts_right' tag,
to color the elements accordingly.

Expand Down Expand Up @@ -1201,35 +1201,43 @@ def draw_checkmark(self, width: Union[float, int], height: Union[float, int], si

return requires_recoloring

def draw_dropdown_arrow(self, x_position: Union[int, float], y_position: Union[int, float], size: Union[int, float]) -> bool:
""" Draws a dropdown bottom facing arrow at (x_position, y_position) in a given size
def draw_arrow(self, x_position: Union[int, float], y_position: Union[int, float],
size: Union[int, float], direction: Literal["down", "up"] = "down") -> bool:
""" Draws an arrow at (x_position, y_position) in a given size and with required direction

returns bool if recoloring is necessary """

x_position, y_position, size = round(x_position), round(y_position), round(size)
requires_recoloring = False

if direction=="down":
name = "dropdown_arrow"
elif direction=="up":
name = "dropup_arrow"

if self.preferred_drawing_method == "polygon_shapes" or self.preferred_drawing_method == "circle_shapes":
if not self._canvas.find_withtag("dropdown_arrow"):
self._canvas.create_line(0, 0, 0, 0, tags="dropdown_arrow", width=round(size / 3), joinstyle=tkinter.ROUND, capstyle=tkinter.ROUND)
self._canvas.tag_raise("dropdown_arrow")
if not self._canvas.find_withtag(name):
self._canvas.create_line(0, 0, 0, 0, tags=name, width=round(size / 3), joinstyle=tkinter.ROUND, capstyle=tkinter.ROUND)
self._canvas.tag_raise(name)
requires_recoloring = True

self._canvas.coords("dropdown_arrow",
ymul = -1 if direction=="up" else 1
self._canvas.coords(name,
x_position - (size / 2),
y_position - (size / 5),
y_position - (size / 5) * ymul,
x_position,
y_position + (size / 5),
y_position + (size / 5) * ymul,
x_position + (size / 2),
y_position - (size / 5))
y_position - (size / 5) * ymul)

elif self.preferred_drawing_method == "font_shapes":
if not self._canvas.find_withtag("dropdown_arrow"):
self._canvas.create_text(0, 0, text="Y", font=("CustomTkinter_shapes_font", -size), tags="dropdown_arrow", anchor=tkinter.CENTER)
self._canvas.tag_raise("dropdown_arrow")
if not self._canvas.find_withtag(name):
self._canvas.create_text(0, 0, text="Y", angle=(180 if direction=="up" else 0),
font=("CustomTkinter_shapes_font", -size), tags=name, anchor=tkinter.CENTER)
self._canvas.tag_raise(name)
requires_recoloring = True

self._canvas.itemconfigure("dropdown_arrow", font=("CustomTkinter_shapes_font", -size))
self._canvas.coords("dropdown_arrow", x_position, y_position)
self._canvas.itemconfigure(name, font=("CustomTkinter_shapes_font", -size))
self._canvas.coords(name, x_position, y_position)

return requires_recoloring
2 changes: 1 addition & 1 deletion customtkinter/windows/widgets/ctk_combobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _draw(self, no_color_updates=False):
self._apply_widget_scaling(self._border_width),
self._apply_widget_scaling(left_section_width))

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_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 / 3))

Expand Down
2 changes: 1 addition & 1 deletion customtkinter/windows/widgets/ctk_optionmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _draw(self, no_color_updates=False):
0,
self._apply_widget_scaling(left_section_width))

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_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 / 3))

Expand Down
Loading