mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
db4f5ec919 | |||
78f4e1e2ee | |||
acaeceb96d | |||
be126c70ae | |||
d45904b1e4 | |||
4fbcce75a0 | |||
92de2c4183 | |||
1c5c3450f9 | |||
c95c0b7050 | |||
de33629e7d | |||
162997c7da | |||
767379462e | |||
a2fcb5dee1 | |||
039cb1d17c | |||
f9890ba3e9 | |||
cdaf8f5f5c | |||
7e8bbf2968 | |||
a3fb12f7cf | |||
bb6678ae15 | |||
b30692d1af | |||
21448d3a07 | |||
1f030f04f9 | |||
c9653e7793 | |||
f587109618 | |||
8bfd763786 | |||
2a0ae06426 | |||
16b9ce3c5f | |||
e15bc5933d | |||
11c7363d28 | |||
d4d0cf1188 | |||
22b4dfb2d3 | |||
9146e02718 | |||
4cf6a9f5c9 | |||
6e36ec818e | |||
0f7cb22b1b |
18
CHANGELOG.md
18
CHANGELOG.md
@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [4.5.0] - 2022-06-23
|
||||
### Added
|
||||
- CTkScrollbar (vertical, horizontal)
|
||||
|
||||
## [4.4.0] - 2022-06-14
|
||||
### Changed
|
||||
- Changed custom dropdown menu to normal tkinter.Menu because of multiple platform specific bugs
|
||||
|
||||
## [4.3.0] - 2022-06-1
|
||||
### Added
|
||||
- Added CTkComboBox
|
||||
- Small fixes for new dropdown menu
|
||||
|
||||
## [4.2.0] - 2022-05-30
|
||||
### Added
|
||||
- CTkOptionMenu with custom dropdown menu
|
||||
- Support for clicking on labels of CTkCheckBox, CTkRadioButton, CTkSwitch
|
||||
|
||||
## [4.1.0] - 2022-05-24
|
||||
### Added
|
||||
- Configure width and height for frame, button, label, progressbar, slider, entry
|
||||
|
@ -1,4 +1,4 @@
|
||||
__version__ = "4.5.0"
|
||||
__version__ = "4.5.5"
|
||||
|
||||
import os
|
||||
import sys
|
||||
@ -49,6 +49,7 @@ if FontManager.load_font(os.path.join(script_directory, "assets", "fonts", "Cust
|
||||
DrawEngine.preferred_drawing_method = "circle_shapes"
|
||||
|
||||
# import widgets
|
||||
from .widgets.widget_base_class import CTkBaseClass
|
||||
from .widgets.ctk_button import CTkButton
|
||||
from .widgets.ctk_checkbox import CTkCheckBox
|
||||
from .widgets.ctk_entry import CTkEntry
|
||||
@ -62,6 +63,7 @@ from .widgets.ctk_switch import CTkSwitch
|
||||
from .widgets.ctk_optionmenu import CTkOptionMenu
|
||||
from .widgets.ctk_combobox import CTkComboBox
|
||||
from .widgets.ctk_scrollbar import CTkScrollbar
|
||||
from .widgets.ctk_textbox import CTkTextbox
|
||||
|
||||
# import windows
|
||||
from .windows.ctk_tk import CTk
|
||||
|
@ -50,7 +50,10 @@ class AppearanceModeTracker:
|
||||
|
||||
@classmethod
|
||||
def remove(cls, callback: Callable):
|
||||
cls.callback_list.remove(callback)
|
||||
try:
|
||||
cls.callback_list.remove(callback)
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def detect_appearance_mode() -> int:
|
||||
|
@ -62,7 +62,7 @@
|
||||
"entry_border_width": 2,
|
||||
"frame_corner_radius": 6,
|
||||
"frame_border_width": 0,
|
||||
"label_corner_radius": 8,
|
||||
"label_corner_radius": 0,
|
||||
"progressbar_border_width": 0,
|
||||
"progressbar_corner_radius": 1000,
|
||||
"slider_border_width": 6,
|
||||
|
@ -62,7 +62,7 @@
|
||||
"entry_border_width": 2,
|
||||
"frame_corner_radius": 10,
|
||||
"frame_border_width": 0,
|
||||
"label_corner_radius": 8,
|
||||
"label_corner_radius": 0,
|
||||
"progressbar_border_width": 0,
|
||||
"progressbar_corner_radius": 1000,
|
||||
"slider_border_width": 6,
|
||||
@ -72,6 +72,8 @@
|
||||
"switch_border_width": 3,
|
||||
"switch_corner_radius": 1000,
|
||||
"switch_button_corner_radius": 1000,
|
||||
"switch_button_length": 0
|
||||
"switch_button_length": 0,
|
||||
"scrollbar_corner_radius": 1000,
|
||||
"scrollbar_border_spacing": 4
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@
|
||||
"entry_border_width": 2,
|
||||
"frame_corner_radius": 10,
|
||||
"frame_border_width": 0,
|
||||
"label_corner_radius": 8,
|
||||
"label_corner_radius": 0,
|
||||
"progressbar_border_width": 0,
|
||||
"progressbar_corner_radius": 1000,
|
||||
"slider_border_width": 6,
|
||||
@ -72,6 +72,8 @@
|
||||
"switch_border_width": 3,
|
||||
"switch_corner_radius": 1000,
|
||||
"switch_button_corner_radius": 1000,
|
||||
"switch_button_length": 0
|
||||
"switch_button_length": 0,
|
||||
"scrollbar_corner_radius": 1000,
|
||||
"scrollbar_border_spacing": 4
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@
|
||||
"entry_border_width": 2,
|
||||
"frame_corner_radius": 10,
|
||||
"frame_border_width": 2,
|
||||
"label_corner_radius": 8,
|
||||
"label_corner_radius": 0,
|
||||
"progressbar_border_width": 2,
|
||||
"progressbar_corner_radius": 1000,
|
||||
"slider_border_width": 6,
|
||||
@ -72,6 +72,8 @@
|
||||
"switch_border_width": 3,
|
||||
"switch_corner_radius": 1000,
|
||||
"switch_button_corner_radius": 1000,
|
||||
"switch_button_length": 2
|
||||
"switch_button_length": 2,
|
||||
"scrollbar_corner_radius": 1000,
|
||||
"scrollbar_border_spacing": 4
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import tkinter
|
||||
import sys
|
||||
import math
|
||||
from typing import Union, Tuple, Callable
|
||||
|
||||
from .ctk_canvas import CTkCanvas
|
||||
from ..theme_manager import ThemeManager
|
||||
@ -10,60 +10,65 @@ from .widget_base_class import CTkBaseClass
|
||||
|
||||
|
||||
class CTkButton(CTkBaseClass):
|
||||
""" tkinter custom button with border, rounded corners and hover effect """
|
||||
""" button with border, rounded corners, hover effect, image support """
|
||||
|
||||
def __init__(self, *args,
|
||||
bg_color=None,
|
||||
fg_color="default_theme",
|
||||
hover_color="default_theme",
|
||||
border_color="default_theme",
|
||||
border_width="default_theme",
|
||||
command=None,
|
||||
textvariable=None,
|
||||
width=140,
|
||||
height=28,
|
||||
corner_radius="default_theme",
|
||||
text_font="default_theme",
|
||||
text_color="default_theme",
|
||||
text_color_disabled="default_theme",
|
||||
text="CTkButton",
|
||||
hover=True,
|
||||
image=None,
|
||||
compound=tkinter.LEFT,
|
||||
state=tkinter.NORMAL,
|
||||
bg_color: Union[str, Tuple[str, str], None] = None,
|
||||
fg_color: Union[str, Tuple[str, str], None] = "default_theme",
|
||||
hover_color: Union[str, Tuple[str, str]] = "default_theme",
|
||||
border_color: Union[str, Tuple[str, str]] = "default_theme",
|
||||
text_color: Union[str, Tuple[str, str]] = "default_theme",
|
||||
text_color_disabled: Union[str, Tuple[str, str]] = "default_theme",
|
||||
width: int = 140,
|
||||
height: int = 28,
|
||||
corner_radius: Union[int, str] = "default_theme",
|
||||
border_width: Union[int, str] = "default_theme",
|
||||
text: str = "CTkButton",
|
||||
textvariable: tkinter.Variable = None,
|
||||
text_font: any = "default_theme",
|
||||
image: tkinter.PhotoImage = None,
|
||||
hover: bool = True,
|
||||
compound: str = "left",
|
||||
state: str = "normal",
|
||||
command: Callable = None,
|
||||
**kwargs):
|
||||
|
||||
# transfer basic functionality (bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs)
|
||||
|
||||
self.configure_basic_grid()
|
||||
|
||||
# color variables
|
||||
# color
|
||||
self.fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
||||
self.hover_color = ThemeManager.theme["color"]["button_hover"] if hover_color == "default_theme" else hover_color
|
||||
self.border_color = ThemeManager.theme["color"]["button_border"] if border_color == "default_theme" else border_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
|
||||
|
||||
# shape
|
||||
self.corner_radius = ThemeManager.theme["shape"]["button_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
||||
self.border_width = ThemeManager.theme["shape"]["button_border_width"] if border_width == "default_theme" else border_width
|
||||
|
||||
# text and font and image
|
||||
# text, font, image
|
||||
self.image = image
|
||||
self.image_label = None
|
||||
self.text = text
|
||||
self.text_label = None
|
||||
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_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||
|
||||
# callback and hover functionality
|
||||
self.function = command
|
||||
self.command = command
|
||||
self.textvariable = textvariable
|
||||
self.state = state
|
||||
self.hover = hover
|
||||
self.compound = compound
|
||||
self.click_animation_running = False
|
||||
|
||||
# configure grid system (2x2)
|
||||
self.grid_rowconfigure(0, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
self.grid_rowconfigure(1, weight=1)
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
|
||||
# canvas
|
||||
self.canvas = CTkCanvas(master=self,
|
||||
highlightthickness=0,
|
||||
width=self.apply_widget_scaling(self._desired_width),
|
||||
@ -71,22 +76,16 @@ class CTkButton(CTkBaseClass):
|
||||
self.canvas.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="nsew")
|
||||
self.draw_engine = DrawEngine(self.canvas)
|
||||
|
||||
# event bindings
|
||||
# canvas event bindings
|
||||
self.canvas.bind("<Enter>", self.on_enter)
|
||||
self.canvas.bind("<Leave>", self.on_leave)
|
||||
self.canvas.bind("<Button-1>", self.clicked)
|
||||
self.canvas.bind("<Button-1>", self.clicked)
|
||||
self.bind('<Configure>', self.update_dimensions_event)
|
||||
|
||||
# configure cursor and initial draw
|
||||
self.set_cursor()
|
||||
self.draw() # initial draw
|
||||
|
||||
def configure_basic_grid(self):
|
||||
# Configuration of a grid system (2x2) in which all parts of CTkButton are centered
|
||||
self.grid_rowconfigure(0, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
self.grid_rowconfigure(1, weight=1)
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
self.draw()
|
||||
|
||||
def set_scaling(self, *args, **kwargs):
|
||||
super().set_scaling(*args, **kwargs)
|
||||
@ -102,7 +101,7 @@ class CTkButton(CTkBaseClass):
|
||||
height=self.apply_widget_scaling(self._desired_height))
|
||||
self.draw()
|
||||
|
||||
def set_dimensions(self, width=None, height=None):
|
||||
def set_dimensions(self, width: int = None, height: int = None):
|
||||
super().set_dimensions(width, height)
|
||||
|
||||
self.canvas.configure(width=self.apply_widget_scaling(self._desired_width),
|
||||
@ -140,6 +139,7 @@ class CTkButton(CTkBaseClass):
|
||||
if self.text_label is None:
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
font=self.apply_font_scaling(self.text_font),
|
||||
text=self.text,
|
||||
textvariable=self.textvariable)
|
||||
|
||||
self.text_label.bind("<Enter>", self.on_enter)
|
||||
@ -161,8 +161,6 @@ class CTkButton(CTkBaseClass):
|
||||
else:
|
||||
self.text_label.configure(bg=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
||||
|
||||
self.text_label.configure(text=self.text) # set text
|
||||
|
||||
else:
|
||||
# delete text_label if no text given
|
||||
if self.text_label is not None:
|
||||
@ -237,102 +235,82 @@ class CTkButton(CTkBaseClass):
|
||||
padx=max(self.apply_widget_scaling(self.corner_radius), self.apply_widget_scaling(self.border_width)),
|
||||
pady=(self.apply_widget_scaling(self.border_width), 2))
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "text" in kwargs:
|
||||
self.set_text(kwargs["text"])
|
||||
del kwargs["text"]
|
||||
self.text = kwargs.pop("text")
|
||||
if self.text_label is None:
|
||||
require_redraw = True # text_label will be created in .draw()
|
||||
else:
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs["state"]
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
require_redraw = True
|
||||
del kwargs["state"]
|
||||
|
||||
if "image" in kwargs:
|
||||
self.set_image(kwargs["image"])
|
||||
del kwargs["image"]
|
||||
self.image = kwargs.pop("image")
|
||||
require_redraw = True
|
||||
|
||||
if "compound" in kwargs:
|
||||
self.compound = kwargs["compound"]
|
||||
self.compound = kwargs.pop("compound")
|
||||
require_redraw = True
|
||||
del kwargs["compound"]
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
del kwargs["fg_color"]
|
||||
|
||||
if "border_color" in kwargs:
|
||||
self.border_color = kwargs["border_color"]
|
||||
self.border_color = kwargs.pop("border_color")
|
||||
require_redraw = True
|
||||
del kwargs["border_color"]
|
||||
|
||||
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 "hover_color" in kwargs:
|
||||
self.hover_color = kwargs["hover_color"]
|
||||
self.hover_color = kwargs.pop("hover_color")
|
||||
require_redraw = True
|
||||
del kwargs["hover_color"]
|
||||
|
||||
if "text_color" in kwargs:
|
||||
self.text_color = kwargs["text_color"]
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
del kwargs["text_color"]
|
||||
|
||||
if "command" in kwargs:
|
||||
self.function = kwargs["command"]
|
||||
del kwargs["command"]
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
if "textvariable" in kwargs:
|
||||
self.textvariable = kwargs["textvariable"]
|
||||
self.textvariable = kwargs.pop("textvariable")
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(textvariable=self.textvariable)
|
||||
del kwargs["textvariable"]
|
||||
|
||||
if "width" in kwargs:
|
||||
self.set_dimensions(width=kwargs["width"])
|
||||
del kwargs["width"]
|
||||
self.set_dimensions(width=kwargs.pop("width"))
|
||||
|
||||
if "height" in kwargs:
|
||||
self.set_dimensions(height=kwargs["height"])
|
||||
del kwargs["height"]
|
||||
self.set_dimensions(height=kwargs.pop("height"))
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def set_cursor(self):
|
||||
if Settings.cursor_manipulation_enabled:
|
||||
if self.state == tkinter.DISABLED:
|
||||
if sys.platform == "darwin" and self.function is not None and Settings.cursor_manipulation_enabled:
|
||||
if sys.platform == "darwin" and self.command is not None and Settings.cursor_manipulation_enabled:
|
||||
self.configure(cursor="arrow")
|
||||
elif sys.platform.startswith("win") and self.function is not None and Settings.cursor_manipulation_enabled:
|
||||
elif sys.platform.startswith("win") and self.command is not None and Settings.cursor_manipulation_enabled:
|
||||
self.configure(cursor="arrow")
|
||||
|
||||
elif self.state == tkinter.NORMAL:
|
||||
if sys.platform == "darwin" and self.function is not None and Settings.cursor_manipulation_enabled:
|
||||
if sys.platform == "darwin" and self.command is not None and Settings.cursor_manipulation_enabled:
|
||||
self.configure(cursor="pointinghand")
|
||||
elif sys.platform.startswith("win") and self.function is not None and Settings.cursor_manipulation_enabled:
|
||||
elif sys.platform.startswith("win") and self.command is not None and Settings.cursor_manipulation_enabled:
|
||||
self.configure(cursor="hand2")
|
||||
|
||||
def set_text(self, text):
|
||||
self.text = text
|
||||
self.draw()
|
||||
|
||||
def set_image(self, image):
|
||||
self.image = image
|
||||
self.draw()
|
||||
""" will be removed in next major """
|
||||
self.configure(image=image)
|
||||
|
||||
def on_enter(self, event=0):
|
||||
def set_text(self, text):
|
||||
""" will be removed in next major """
|
||||
self.configure(text=text)
|
||||
|
||||
def on_enter(self, event=None):
|
||||
if self.hover is True and self.state == tkinter.NORMAL:
|
||||
if self.hover_color is None:
|
||||
inner_parts_color = self.fg_color
|
||||
@ -352,7 +330,7 @@ class CTkButton(CTkBaseClass):
|
||||
if self.image_label is not None:
|
||||
self.image_label.configure(bg=ThemeManager.single_color(inner_parts_color, self._appearance_mode))
|
||||
|
||||
def on_leave(self, event=0):
|
||||
def on_leave(self, event=None):
|
||||
self.click_animation_running = False
|
||||
|
||||
if self.hover is True:
|
||||
@ -378,8 +356,8 @@ class CTkButton(CTkBaseClass):
|
||||
if self.click_animation_running:
|
||||
self.on_enter()
|
||||
|
||||
def clicked(self, event=0):
|
||||
if self.function is not None:
|
||||
def clicked(self, event=None):
|
||||
if self.command is not None:
|
||||
if self.state is not tkinter.DISABLED:
|
||||
|
||||
# click animation: change color with .on_leave() and back to normal after 100ms with click_animation()
|
||||
@ -387,4 +365,4 @@ class CTkButton(CTkBaseClass):
|
||||
self.click_animation_running = True
|
||||
self.after(100, self.click_animation)
|
||||
|
||||
self.function()
|
||||
self.command()
|
||||
|
@ -8,7 +8,6 @@ class CTkCanvas(tkinter.Canvas):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.aa_circle_canvas_ids = set()
|
||||
|
||||
@classmethod
|
||||
|
@ -56,15 +56,16 @@ class CTkCheckBox(CTkBaseClass):
|
||||
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||
|
||||
# callback and hover functionality
|
||||
self.function = command
|
||||
self.command = command
|
||||
self.state = state
|
||||
self.hover = hover
|
||||
self.check_state = False
|
||||
|
||||
self.onvalue = onvalue
|
||||
self.offvalue = offvalue
|
||||
self.variable: tkinter.Variable = variable
|
||||
self.variable_callback_blocked = False
|
||||
self.textvariable = textvariable
|
||||
self.textvariable: tkinter.Variable = textvariable
|
||||
self.variable_callback_name = None
|
||||
|
||||
# configure grid system (1x3)
|
||||
@ -90,13 +91,23 @@ class CTkCheckBox(CTkBaseClass):
|
||||
self.canvas.bind("<Leave>", self.on_leave)
|
||||
self.canvas.bind("<Button-1>", self.toggle)
|
||||
|
||||
# set select state according to variable
|
||||
if self.variable is not None:
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
bd=0,
|
||||
text=self.text,
|
||||
justify=tkinter.LEFT,
|
||||
font=self.apply_font_scaling(self.text_font),
|
||||
textvariable=self.textvariable)
|
||||
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
||||
self.text_label["anchor"] = "w"
|
||||
|
||||
self.text_label.bind("<Enter>", self.on_enter)
|
||||
self.text_label.bind("<Leave>", self.on_leave)
|
||||
self.text_label.bind("<Button-1>", self.toggle)
|
||||
|
||||
# register variable callback and set state according to variable
|
||||
if self.variable is not None and self.variable != "":
|
||||
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
||||
if self.variable.get() == self.onvalue:
|
||||
self.select(from_variable_callback=True)
|
||||
elif self.variable.get() == self.offvalue:
|
||||
self.deselect(from_variable_callback=True)
|
||||
self.check_state = True if variable.get() == self.onvalue else False
|
||||
|
||||
self.draw() # initial draw
|
||||
self.set_cursor()
|
||||
@ -153,93 +164,58 @@ class CTkCheckBox(CTkBaseClass):
|
||||
outline=ThemeManager.single_color(self.border_color, self._appearance_mode),
|
||||
fill=ThemeManager.single_color(self.border_color, self._appearance_mode))
|
||||
|
||||
if self.text_label is None:
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
bd=0,
|
||||
text=self.text,
|
||||
justify=tkinter.LEFT,
|
||||
font=self.apply_font_scaling(self.text_font))
|
||||
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
||||
self.text_label["anchor"] = "w"
|
||||
|
||||
self.text_label.bind("<Enter>", self.on_enter)
|
||||
self.text_label.bind("<Leave>", self.on_leave)
|
||||
self.text_label.bind("<Button-1>", self.toggle)
|
||||
|
||||
if self.state == tkinter.DISABLED:
|
||||
self.text_label.configure(fg=(ThemeManager.single_color(self.text_color_disabled, self._appearance_mode)))
|
||||
else:
|
||||
self.text_label.configure(fg=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
||||
|
||||
self.text_label.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
|
||||
self.set_text(self.text)
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw()
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "text" in kwargs:
|
||||
self.set_text(kwargs["text"])
|
||||
del kwargs["text"]
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs["state"]
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
require_redraw = True
|
||||
del kwargs["state"]
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
del kwargs["fg_color"]
|
||||
|
||||
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 "hover_color" in kwargs:
|
||||
self.hover_color = kwargs["hover_color"]
|
||||
self.hover_color = kwargs.pop("hover_color")
|
||||
require_redraw = True
|
||||
del kwargs["hover_color"]
|
||||
|
||||
if "text_color" in kwargs:
|
||||
self.text_color = kwargs["text_color"]
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
del kwargs["text_color"]
|
||||
|
||||
if "border_color" in kwargs:
|
||||
self.border_color = kwargs["border_color"]
|
||||
self.border_color = kwargs.pop("border_color")
|
||||
require_redraw = True
|
||||
del kwargs["border_color"]
|
||||
|
||||
if "command" in kwargs:
|
||||
self.function = kwargs["command"]
|
||||
del kwargs["command"]
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
if "textvariable" in kwargs:
|
||||
self.textvariable = kwargs.pop("textvariable")
|
||||
self.text_label.configure(textvariable=self.textvariable)
|
||||
|
||||
if "variable" in kwargs:
|
||||
if self.variable is not None:
|
||||
self.variable.trace_remove("write", self.variable_callback_name)
|
||||
if self.variable is not None and self.variable != "":
|
||||
self.variable.trace_remove("write", self.variable_callback_name) # remove old variable callback
|
||||
|
||||
self.variable = kwargs["variable"]
|
||||
self.variable = kwargs.pop("variable")
|
||||
|
||||
if self.variable is not None and self.variable != "":
|
||||
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
||||
if self.variable.get() == self.onvalue:
|
||||
self.select(from_variable_callback=True)
|
||||
elif self.variable.get() == self.offvalue:
|
||||
self.deselect(from_variable_callback=True)
|
||||
else:
|
||||
self.variable = None
|
||||
self.check_state = True if self.variable.get() == self.onvalue else False
|
||||
require_redraw = True
|
||||
|
||||
del kwargs["variable"]
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def set_cursor(self):
|
||||
if Settings.cursor_manipulation_enabled:
|
||||
@ -263,13 +239,6 @@ class CTkCheckBox(CTkBaseClass):
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(cursor="hand2")
|
||||
|
||||
def set_text(self, text):
|
||||
self.text = text
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(text=self.text)
|
||||
else:
|
||||
sys.stderr.write("ERROR (CTkButton): Cant change text because checkbox has no text.")
|
||||
|
||||
def on_enter(self, event=0):
|
||||
if self.hover is True and self.state == tkinter.NORMAL:
|
||||
if self.check_state is True:
|
||||
@ -317,14 +286,14 @@ class CTkCheckBox(CTkBaseClass):
|
||||
self.check_state = True
|
||||
self.draw()
|
||||
|
||||
if self.function is not None:
|
||||
self.function()
|
||||
|
||||
if self.variable is not None:
|
||||
self.variable_callback_blocked = True
|
||||
self.variable.set(self.onvalue if self.check_state is True else self.offvalue)
|
||||
self.variable_callback_blocked = False
|
||||
|
||||
if self.command is not None:
|
||||
self.command()
|
||||
|
||||
def select(self, from_variable_callback=False):
|
||||
self.check_state = True
|
||||
self.draw()
|
||||
@ -334,8 +303,8 @@ class CTkCheckBox(CTkBaseClass):
|
||||
self.variable.set(self.onvalue)
|
||||
self.variable_callback_blocked = False
|
||||
|
||||
if self.function is not None:
|
||||
self.function()
|
||||
if self.command is not None:
|
||||
self.command()
|
||||
|
||||
def deselect(self, from_variable_callback=False):
|
||||
self.check_state = False
|
||||
@ -346,11 +315,8 @@ class CTkCheckBox(CTkBaseClass):
|
||||
self.variable.set(self.offvalue)
|
||||
self.variable_callback_blocked = False
|
||||
|
||||
if self.function is not None:
|
||||
try:
|
||||
self.function()
|
||||
except:
|
||||
pass
|
||||
if self.command is not None:
|
||||
self.command()
|
||||
|
||||
def get(self):
|
||||
return self.onvalue if self.check_state is True else self.offvalue
|
||||
|
@ -1,9 +1,7 @@
|
||||
import tkinter
|
||||
import sys
|
||||
from typing import Union
|
||||
|
||||
from .dropdown_menu import DropdownMenu
|
||||
|
||||
from .ctk_canvas import CTkCanvas
|
||||
from ..theme_manager import ThemeManager
|
||||
from ..settings import Settings
|
||||
@ -55,8 +53,8 @@ class CTkComboBox(CTkBaseClass):
|
||||
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||
|
||||
# callback and hover functionality
|
||||
self.function = command
|
||||
self.variable = variable
|
||||
self.command = command
|
||||
self.textvariable = variable
|
||||
self.state = state
|
||||
self.hover = hover
|
||||
|
||||
@ -114,12 +112,19 @@ class CTkComboBox(CTkBaseClass):
|
||||
self.canvas.tag_bind("dropdown_arrow", "<Button-1>", self.clicked)
|
||||
self.bind('<Configure>', self.update_dimensions_event)
|
||||
|
||||
if self.variable is not None:
|
||||
self.entry.configure(textvariable=self.variable)
|
||||
if self.textvariable is not None:
|
||||
self.entry.configure(textvariable=self.textvariable)
|
||||
|
||||
def set_scaling(self, *args, **kwargs):
|
||||
super().set_scaling(*args, **kwargs)
|
||||
|
||||
# change entry font size and grid padding
|
||||
left_section_width = self._current_width - self._current_height
|
||||
self.entry.configure(font=self.apply_font_scaling(self.text_font))
|
||||
self.entry.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="ew",
|
||||
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))))
|
||||
|
||||
self.canvas.configure(width=self.apply_widget_scaling(self._desired_width),
|
||||
height=self.apply_widget_scaling(self._desired_height))
|
||||
self.draw()
|
||||
@ -176,85 +181,58 @@ class CTkComboBox(CTkBaseClass):
|
||||
self.dropdown_menu.open(self.winfo_rootx(),
|
||||
self.winfo_rooty() + self.apply_widget_scaling(self._current_height + 0))
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs["state"]
|
||||
self.state = kwargs.pop("state")
|
||||
self.entry.configure(state=self.state)
|
||||
require_redraw = True
|
||||
del kwargs["state"]
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
del kwargs["fg_color"]
|
||||
|
||||
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 "button_color" in kwargs:
|
||||
self.button_color = kwargs["button_color"]
|
||||
self.button_color = kwargs.pop("button_color")
|
||||
require_redraw = True
|
||||
del kwargs["button_color"]
|
||||
|
||||
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
|
||||
del kwargs["button_hover_color"]
|
||||
|
||||
if "text_color" in kwargs:
|
||||
self.text_color = kwargs["text_color"]
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
del kwargs["text_color"]
|
||||
|
||||
if "command" in kwargs:
|
||||
self.function = kwargs["command"]
|
||||
del kwargs["command"]
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
if "variable" in kwargs:
|
||||
self.variable = kwargs["variable"]
|
||||
self.entry.configure(textvariable=self.variable)
|
||||
del kwargs["variable"]
|
||||
self.textvariable = kwargs.pop("variable")
|
||||
self.entry.configure(textvariable=self.textvariable)
|
||||
|
||||
if "width" in kwargs:
|
||||
self.set_dimensions(width=kwargs["width"])
|
||||
del kwargs["width"]
|
||||
self.set_dimensions(width=kwargs.pop("width"))
|
||||
|
||||
if "height" in kwargs:
|
||||
self.set_dimensions(height=kwargs["height"])
|
||||
del kwargs["height"]
|
||||
self.set_dimensions(height=kwargs.pop("height"))
|
||||
|
||||
if "values" in kwargs:
|
||||
self.values = kwargs["values"]
|
||||
del kwargs["values"]
|
||||
self.values = kwargs.pop("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"]
|
||||
self.dropdown_menu.configure(fg_color=kwargs.pop("dropdown_color"))
|
||||
|
||||
if "dropdown_hover_color" in kwargs:
|
||||
self.dropdown_menu.configure(hover_color=kwargs["dropdown_hover_color"])
|
||||
del kwargs["dropdown_hover_color"]
|
||||
self.dropdown_menu.configure(hover_color=kwargs.pop("dropdown_hover_color"))
|
||||
|
||||
if "dropdown_text_color" in kwargs:
|
||||
self.dropdown_menu.configure(text_color=kwargs["dropdown_text_color"])
|
||||
del kwargs["dropdown_text_color"]
|
||||
self.dropdown_menu.configure(text_color=kwargs.pop("dropdown_text_color"))
|
||||
|
||||
if "dropdown_text_font" in kwargs:
|
||||
self.dropdown_menu.configure(text_font=kwargs["dropdown_text_font"])
|
||||
del kwargs["dropdown_text_font"]
|
||||
self.dropdown_menu.configure(text_font=kwargs.pop("dropdown_text_font"))
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def on_enter(self, event=0):
|
||||
if self.hover is True and self.state == tkinter.NORMAL and len(self.values) > 0:
|
||||
@ -289,12 +267,18 @@ class CTkComboBox(CTkBaseClass):
|
||||
def set(self, value: str, from_variable_callback: bool = False):
|
||||
self.current_value = value
|
||||
|
||||
self.entry.delete(0, tkinter.END)
|
||||
self.entry.insert(0, self.current_value)
|
||||
if self.state == "readonly":
|
||||
self.entry.configure(state="normal")
|
||||
self.entry.delete(0, tkinter.END)
|
||||
self.entry.insert(0, self.current_value)
|
||||
self.entry.configure(state="readonly")
|
||||
else:
|
||||
self.entry.delete(0, tkinter.END)
|
||||
self.entry.insert(0, self.current_value)
|
||||
|
||||
if not from_variable_callback:
|
||||
if self.function is not None:
|
||||
self.function(self.current_value)
|
||||
if self.command is not None:
|
||||
self.command(self.current_value)
|
||||
|
||||
def get(self) -> str:
|
||||
return self.entry.get()
|
||||
|
@ -20,32 +20,39 @@ class CTkEntry(CTkBaseClass):
|
||||
width=140,
|
||||
height=28,
|
||||
state=tkinter.NORMAL,
|
||||
textvariable: tkinter.Variable = None,
|
||||
**kwargs):
|
||||
|
||||
# transfer basic functionality (bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
||||
if "master" in kwargs:
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height, master=kwargs["master"])
|
||||
del kwargs["master"]
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height, master=kwargs.pop("master"))
|
||||
else:
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height)
|
||||
|
||||
# configure grid system (1x1)
|
||||
self.grid_rowconfigure(0, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
|
||||
# color
|
||||
self.fg_color = ThemeManager.theme["color"]["entry"] if fg_color == "default_theme" else fg_color
|
||||
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
||||
self.placeholder_text_color = ThemeManager.theme["color"]["entry_placeholder_text"] if placeholder_text_color == "default_theme" else placeholder_text_color
|
||||
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||
self.border_color = ThemeManager.theme["color"]["entry_border"] if border_color == "default_theme" else border_color
|
||||
|
||||
# shape
|
||||
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
|
||||
|
||||
# placeholder text
|
||||
self.placeholder_text = placeholder_text
|
||||
self.placeholder_text_active = False
|
||||
self.pre_placeholder_arguments = {} # some set arguments of the entry will be changed for placeholder and then set back
|
||||
|
||||
self.state = state
|
||||
# textvariable
|
||||
self.textvariable = textvariable
|
||||
|
||||
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.state = state
|
||||
|
||||
self.canvas = CTkCanvas(master=self,
|
||||
highlightthickness=0,
|
||||
@ -60,17 +67,18 @@ class CTkEntry(CTkBaseClass):
|
||||
highlightthickness=0,
|
||||
font=self.apply_font_scaling(self.text_font),
|
||||
state=self.state,
|
||||
textvariable=self.textvariable,
|
||||
**kwargs)
|
||||
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),
|
||||
pady=(self.apply_widget_scaling(self.border_width), self.apply_widget_scaling(self.border_width + 1)))
|
||||
|
||||
super().bind('<Configure>', self.update_dimensions_event)
|
||||
self.entry.bind('<FocusOut>', self.set_placeholder)
|
||||
self.entry.bind('<FocusIn>', self.clear_placeholder)
|
||||
self.entry.bind('<FocusOut>', self.entry_focus_out)
|
||||
self.entry.bind('<FocusIn>', self.entry_focus_in)
|
||||
|
||||
self.draw()
|
||||
self.set_placeholder()
|
||||
self.draw()
|
||||
|
||||
def set_scaling(self, *args, **kwargs):
|
||||
super().set_scaling( *args, **kwargs)
|
||||
@ -89,23 +97,6 @@ class CTkEntry(CTkBaseClass):
|
||||
height=self.apply_widget_scaling(self._desired_height))
|
||||
self.draw()
|
||||
|
||||
def set_placeholder(self, event=None):
|
||||
if self.placeholder_text is not None:
|
||||
if not self.placeholder_text_active and self.entry.get() == "":
|
||||
self.placeholder_text_active = True
|
||||
self.pre_placeholder_arguments = {"show": self.entry.cget("show")}
|
||||
self.entry.config(fg=ThemeManager.single_color(self.placeholder_text_color, self._appearance_mode), show="")
|
||||
self.entry.delete(0, tkinter.END)
|
||||
self.entry.insert(0, self.placeholder_text)
|
||||
|
||||
def clear_placeholder(self, event=None):
|
||||
if self.placeholder_text_active:
|
||||
self.placeholder_text_active = False
|
||||
self.entry.config(fg=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
||||
self.entry.delete(0, tkinter.END)
|
||||
for argument, value in self.pre_placeholder_arguments.items():
|
||||
self.entry[argument] = value
|
||||
|
||||
def draw(self, no_color_updates=False):
|
||||
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
|
||||
@ -146,39 +137,25 @@ class CTkEntry(CTkBaseClass):
|
||||
def bind(self, *args, **kwargs):
|
||||
self.entry.bind(*args, **kwargs)
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs["state"]
|
||||
self.state = kwargs.pop("state")
|
||||
self.entry.configure(state=self.state)
|
||||
del kwargs["state"]
|
||||
|
||||
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"]
|
||||
del kwargs["fg_color"]
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
|
||||
if "text_color" in kwargs:
|
||||
self.text_color = kwargs["text_color"]
|
||||
del kwargs["text_color"]
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
|
||||
if "border_color" in kwargs:
|
||||
self.border_color = kwargs["border_color"]
|
||||
del kwargs["border_color"]
|
||||
self.border_color = kwargs.pop("border_color")
|
||||
require_redraw = True
|
||||
|
||||
if "corner_radius" in kwargs:
|
||||
self.corner_radius = kwargs["corner_radius"]
|
||||
self.corner_radius = kwargs.pop("corner_radius")
|
||||
|
||||
if self.corner_radius * 2 > self._current_height:
|
||||
self.corner_radius = self._current_height / 2
|
||||
@ -186,31 +163,74 @@ class CTkEntry(CTkBaseClass):
|
||||
self.corner_radius = self._current_width / 2
|
||||
|
||||
self.entry.grid(column=0, row=0, sticky="we", padx=self.apply_widget_scaling(self.corner_radius) if self.corner_radius >= 6 else self.apply_widget_scaling(6))
|
||||
del kwargs["corner_radius"]
|
||||
require_redraw = True
|
||||
|
||||
if "width" in kwargs:
|
||||
self.set_dimensions(width=kwargs["width"])
|
||||
del kwargs["width"]
|
||||
self.set_dimensions(width=kwargs.pop("width"))
|
||||
|
||||
if "height" in kwargs:
|
||||
self.set_dimensions(height=kwargs["height"])
|
||||
del kwargs["height"]
|
||||
self.set_dimensions(height=kwargs.pop("height"))
|
||||
|
||||
if "placeholder_text" in kwargs:
|
||||
pass
|
||||
self.placeholder_text = kwargs.pop("placeholder_text")
|
||||
if self.placeholder_text_active:
|
||||
self.entry.delete(0, tkinter.END)
|
||||
self.entry.insert(0, self.placeholder_text)
|
||||
|
||||
self.entry.configure(*args, **kwargs)
|
||||
if "placeholder_text_color" in kwargs:
|
||||
self.placeholder_text_color = kwargs.pop("placeholder_text_color")
|
||||
require_redraw = True
|
||||
|
||||
if require_redraw is True:
|
||||
self.draw()
|
||||
if "textvariable" in kwargs:
|
||||
self.textvariable = kwargs.pop("textvariable")
|
||||
self.entry.configure(textvariable=self.textvariable)
|
||||
|
||||
if "show" in kwargs:
|
||||
if self.placeholder_text_active:
|
||||
self.pre_placeholder_arguments["show"] = kwargs.pop("show")
|
||||
else:
|
||||
self.entry.configure(show=kwargs.pop("show"))
|
||||
|
||||
if "bg_color" in kwargs:
|
||||
super().configure(bg_color=kwargs.pop("bg_color"), require_redraw=require_redraw)
|
||||
else:
|
||||
super().configure(require_redraw=require_redraw)
|
||||
|
||||
self.entry.configure(**kwargs) # pass remaining kwargs to entry
|
||||
|
||||
def set_placeholder(self):
|
||||
if self.entry.get() == "" and self.placeholder_text is not None and (self.textvariable is None or self.textvariable == ""):
|
||||
self.placeholder_text_active = True
|
||||
|
||||
self.pre_placeholder_arguments = {"show": self.entry.cget("show")}
|
||||
self.entry.config(fg=ThemeManager.single_color(self.placeholder_text_color, self._appearance_mode), show="")
|
||||
self.entry.delete(0, tkinter.END)
|
||||
self.entry.insert(0, self.placeholder_text)
|
||||
|
||||
def clear_placeholder(self):
|
||||
if self.placeholder_text_active:
|
||||
self.placeholder_text_active = False
|
||||
|
||||
self.entry.config(fg=ThemeManager.single_color(self.text_color, self._appearance_mode))
|
||||
self.entry.delete(0, tkinter.END)
|
||||
for argument, value in self.pre_placeholder_arguments.items():
|
||||
self.entry[argument] = value
|
||||
|
||||
def entry_focus_out(self, event=None):
|
||||
self.set_placeholder()
|
||||
|
||||
def entry_focus_in(self, event=None):
|
||||
self.clear_placeholder()
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.entry.delete(*args, **kwargs)
|
||||
self.set_placeholder()
|
||||
|
||||
if self.entry.get() == "":
|
||||
self.set_placeholder()
|
||||
|
||||
def insert(self, *args, **kwargs):
|
||||
self.clear_placeholder()
|
||||
|
||||
return self.entry.insert(*args, **kwargs)
|
||||
|
||||
def get(self):
|
||||
@ -218,3 +238,9 @@ class CTkEntry(CTkBaseClass):
|
||||
return ""
|
||||
else:
|
||||
return self.entry.get()
|
||||
|
||||
def focus(self):
|
||||
self.entry.focus()
|
||||
|
||||
def focus_force(self):
|
||||
self.entry.focus_force()
|
||||
|
@ -101,52 +101,32 @@ class CTkFrame(CTkBaseClass):
|
||||
self.canvas.tag_lower("inner_parts")
|
||||
self.canvas.tag_lower("border_parts")
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
del kwargs["fg_color"]
|
||||
|
||||
# check if CTk widgets are children of the frame and change their bg_color to new frame fg_color
|
||||
for child in self.winfo_children():
|
||||
if isinstance(child, CTkBaseClass):
|
||||
child.configure(bg_color=self.fg_color)
|
||||
|
||||
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 "border_color" in kwargs:
|
||||
self.border_color = kwargs["border_color"]
|
||||
self.border_color = kwargs.pop("border_color")
|
||||
require_redraw = True
|
||||
del kwargs["border_color"]
|
||||
|
||||
if "corner_radius" in kwargs:
|
||||
self.corner_radius = kwargs["corner_radius"]
|
||||
self.corner_radius = kwargs.pop("corner_radius")
|
||||
require_redraw = True
|
||||
del kwargs["corner_radius"]
|
||||
|
||||
if "border_width" in kwargs:
|
||||
self.border_width = kwargs["border_width"]
|
||||
self.border_width = kwargs.pop("border_width")
|
||||
require_redraw = True
|
||||
del kwargs["border_width"]
|
||||
|
||||
if "width" in kwargs:
|
||||
self.set_dimensions(width=kwargs["width"])
|
||||
del kwargs["width"]
|
||||
self.set_dimensions(width=kwargs.pop("width"))
|
||||
|
||||
if "height" in kwargs:
|
||||
self.set_dimensions(height=kwargs["height"])
|
||||
del kwargs["height"]
|
||||
self.set_dimensions(height=kwargs.pop("height"))
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import sys
|
||||
import tkinter
|
||||
|
||||
from .ctk_canvas import CTkCanvas
|
||||
@ -16,12 +17,12 @@ class CTkLabel(CTkBaseClass):
|
||||
height=28,
|
||||
text="CTkLabel",
|
||||
text_font="default_theme",
|
||||
anchor="center", # label anchor: center, n, e, s, w
|
||||
**kwargs):
|
||||
|
||||
# transfer basic functionality (bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
||||
if "master" in kwargs:
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height, master=kwargs["master"])
|
||||
del kwargs["master"]
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height, master=kwargs.pop("master"))
|
||||
else:
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height)
|
||||
|
||||
@ -35,6 +36,7 @@ class CTkLabel(CTkBaseClass):
|
||||
self.corner_radius = ThemeManager.theme["shape"]["label_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
||||
|
||||
# text
|
||||
self.anchor = anchor
|
||||
self.text = text
|
||||
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||
|
||||
@ -52,10 +54,13 @@ class CTkLabel(CTkBaseClass):
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
highlightthickness=0,
|
||||
bd=0,
|
||||
anchor=self.anchor,
|
||||
text=self.text,
|
||||
font=self.apply_font_scaling(self.text_font),
|
||||
**kwargs)
|
||||
self.text_label.grid(row=0, column=0, padx=self.apply_widget_scaling(self.corner_radius))
|
||||
text_label_grid_sticky = self.anchor if self.anchor != "center" else ""
|
||||
self.text_label.grid(row=0, column=0, padx=self.apply_widget_scaling(self.corner_radius),
|
||||
sticky=text_label_grid_sticky)
|
||||
|
||||
self.bind('<Configure>', self.update_dimensions_event)
|
||||
self.draw()
|
||||
@ -65,7 +70,9 @@ class CTkLabel(CTkBaseClass):
|
||||
|
||||
self.canvas.configure(width=self.apply_widget_scaling(self._desired_width), height=self.apply_widget_scaling(self._desired_height))
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
self.text_label.grid(row=0, column=0, padx=self.apply_widget_scaling(self.corner_radius))
|
||||
text_label_grid_sticky = self.anchor if self.anchor != "center" else ""
|
||||
self.text_label.grid(row=0, column=0, padx=self.apply_widget_scaling(self.corner_radius),
|
||||
sticky=text_label_grid_sticky)
|
||||
|
||||
self.draw()
|
||||
|
||||
@ -100,8 +107,16 @@ class CTkLabel(CTkBaseClass):
|
||||
|
||||
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
def config(self, **kwargs):
|
||||
sys.stderr.write("Warning: Use .configure() instead of .config()")
|
||||
self.configure(**kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "anchor" in kwargs:
|
||||
self.anchor = kwargs.pop("anchor")
|
||||
text_label_grid_sticky = self.anchor if self.anchor != "center" else ""
|
||||
self.text_label.grid(row=0, column=0, padx=self.apply_widget_scaling(self.corner_radius),
|
||||
sticky=text_label_grid_sticky)
|
||||
|
||||
if "text" in kwargs:
|
||||
self.set_text(kwargs["text"])
|
||||
@ -112,14 +127,6 @@ class CTkLabel(CTkBaseClass):
|
||||
require_redraw = True
|
||||
del kwargs["fg_color"]
|
||||
|
||||
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 "text_color" in kwargs:
|
||||
self.text_color = kwargs["text_color"]
|
||||
require_redraw = True
|
||||
@ -133,10 +140,12 @@ class CTkLabel(CTkBaseClass):
|
||||
self.set_dimensions(height=kwargs["height"])
|
||||
del kwargs["height"]
|
||||
|
||||
self.text_label.configure(*args, **kwargs)
|
||||
if "bg_color" in kwargs:
|
||||
super().configure(bg_color=kwargs.pop("bg_color"), require_redraw=require_redraw)
|
||||
else:
|
||||
super().configure(require_redraw=require_redraw)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
self.text_label.configure(**kwargs) # pass remaining kwargs to label
|
||||
|
||||
def set_text(self, text):
|
||||
self.text = text
|
||||
|
@ -52,7 +52,7 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.dropdown_text_font = dropdown_text_font
|
||||
|
||||
# callback and hover functionality
|
||||
self.function = command
|
||||
self.command = command
|
||||
self.variable = variable
|
||||
self.variable_callback_blocked = False
|
||||
self.variable_callback_name = None
|
||||
@ -90,7 +90,10 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
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 = tkinter.Label(master=self,
|
||||
font=self.apply_font_scaling(self.text_font),
|
||||
anchor="w",
|
||||
text=self.current_value)
|
||||
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))))
|
||||
@ -126,9 +129,12 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
def set_scaling(self, *args, **kwargs):
|
||||
super().set_scaling(*args, **kwargs)
|
||||
|
||||
if self.text_label is not None:
|
||||
self.text_label.destroy()
|
||||
self.text_label = None
|
||||
# change label text size and grid padding
|
||||
left_section_width = self._current_width - self._current_height
|
||||
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
||||
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))))
|
||||
|
||||
self.canvas.configure(width=self.apply_widget_scaling(self._desired_width),
|
||||
height=self.apply_widget_scaling(self._desired_height))
|
||||
@ -153,9 +159,6 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.apply_widget_scaling(self._current_height / 2),
|
||||
self.apply_widget_scaling(self._current_height / 3))
|
||||
|
||||
if self.current_value is not None:
|
||||
self.text_label.configure(text=self.current_value)
|
||||
|
||||
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))
|
||||
@ -186,9 +189,7 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.dropdown_menu.open(self.winfo_rootx(),
|
||||
self.winfo_rooty() + self.apply_widget_scaling(self._current_height + 0))
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs.pop("state")
|
||||
require_redraw = True
|
||||
@ -197,14 +198,6 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
|
||||
if "bg_color" in kwargs:
|
||||
new_bg_color = kwargs.pop("bg_color")
|
||||
if new_bg_color is None:
|
||||
self.bg_color = self.detect_color_of_master()
|
||||
else:
|
||||
self.bg_color = new_bg_color
|
||||
require_redraw = True
|
||||
|
||||
if "button_color" in kwargs:
|
||||
self.button_color = kwargs.pop("button_color")
|
||||
require_redraw = True
|
||||
@ -218,7 +211,7 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
require_redraw = True
|
||||
|
||||
if "command" in kwargs:
|
||||
self.function = kwargs.pop("command")
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
if "variable" in kwargs:
|
||||
if self.variable is not None: # remove old callback
|
||||
@ -261,10 +254,7 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
else:
|
||||
self.grid_propagate(1)
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def on_enter(self, event=0):
|
||||
if self.hover is True and self.state == tkinter.NORMAL and len(self.values) > 0:
|
||||
@ -287,10 +277,7 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
def set(self, value: str, from_variable_callback: bool = False):
|
||||
self.current_value = value
|
||||
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(text=self.current_value)
|
||||
else:
|
||||
self.draw()
|
||||
self.text_label.configure(text=self.current_value)
|
||||
|
||||
if self.variable is not None and not from_variable_callback:
|
||||
self.variable_callback_blocked = True
|
||||
@ -298,8 +285,8 @@ class CTkOptionMenu(CTkBaseClass):
|
||||
self.variable_callback_blocked = False
|
||||
|
||||
if not from_variable_callback:
|
||||
if self.function is not None:
|
||||
self.function(self.current_value)
|
||||
if self.command is not None:
|
||||
self.command(self.current_value)
|
||||
|
||||
def get(self) -> str:
|
||||
return self.current_value
|
||||
|
@ -120,17 +120,7 @@ class CTkProgressBar(CTkBaseClass):
|
||||
fill=ThemeManager.single_color(self.progress_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self.progress_color, self._appearance_mode))
|
||||
|
||||
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"]
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
del kwargs["fg_color"]
|
||||
@ -173,10 +163,7 @@ class CTkProgressBar(CTkBaseClass):
|
||||
self.set_dimensions(height=kwargs["height"])
|
||||
del kwargs["height"]
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw is True:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def variable_callback(self, var_name, index, mode):
|
||||
if not self.variable_callback_blocked:
|
||||
|
@ -1,6 +1,6 @@
|
||||
import tkinter
|
||||
import sys
|
||||
from typing import Callable, Union
|
||||
from typing import Union
|
||||
|
||||
from .ctk_canvas import CTkCanvas
|
||||
from ..theme_manager import ThemeManager
|
||||
@ -54,7 +54,7 @@ class CTkRadioButton(CTkBaseClass):
|
||||
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||
|
||||
# callback and control variables
|
||||
self.function = command
|
||||
self.command = command
|
||||
self.state = state
|
||||
self.hover = hover
|
||||
self.check_state = False
|
||||
@ -86,15 +86,25 @@ class CTkRadioButton(CTkBaseClass):
|
||||
self.canvas.bind("<Leave>", self.on_leave)
|
||||
self.canvas.bind("<Button-1>", self.invoke)
|
||||
|
||||
self.draw() # initial draw
|
||||
self.set_cursor()
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
bd=0,
|
||||
text=self.text,
|
||||
justify=tkinter.LEFT,
|
||||
font=self.apply_font_scaling(self.text_font),
|
||||
textvariable=self.textvariable)
|
||||
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
||||
self.text_label["anchor"] = "w"
|
||||
|
||||
self.text_label.bind("<Enter>", self.on_enter)
|
||||
self.text_label.bind("<Leave>", self.on_leave)
|
||||
self.text_label.bind("<Button-1>", self.invoke)
|
||||
|
||||
if self.variable is not None:
|
||||
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
||||
if self.variable.get() == self.value:
|
||||
self.select(from_variable_callback=True)
|
||||
else:
|
||||
self.deselect(from_variable_callback=True)
|
||||
self.check_state = True if self.variable.get() == self.value else False
|
||||
|
||||
self.draw() # initial draw
|
||||
self.set_cursor()
|
||||
|
||||
def set_scaling(self, *args, **kwargs):
|
||||
super().set_scaling(*args, **kwargs)
|
||||
@ -134,19 +144,6 @@ class CTkRadioButton(CTkBaseClass):
|
||||
outline=ThemeManager.single_color(self.bg_color, self._appearance_mode),
|
||||
fill=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
|
||||
if self.text_label is None:
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
bd=0,
|
||||
text=self.text,
|
||||
justify=tkinter.LEFT,
|
||||
font=self.apply_font_scaling(self.text_font))
|
||||
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
||||
self.text_label["anchor"] = "w"
|
||||
|
||||
self.text_label.bind("<Enter>", self.on_enter)
|
||||
self.text_label.bind("<Leave>", self.on_leave)
|
||||
self.text_label.bind("<Button-1>", self.invoke)
|
||||
|
||||
if self.state == tkinter.DISABLED:
|
||||
self.text_label.configure(fg=ThemeManager.single_color(self.text_color_disabled, self._appearance_mode))
|
||||
else:
|
||||
@ -154,79 +151,55 @@ class CTkRadioButton(CTkBaseClass):
|
||||
|
||||
self.text_label.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
|
||||
self.set_text(self.text)
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw()
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "text" in kwargs:
|
||||
self.set_text(kwargs["text"])
|
||||
del kwargs["text"]
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs["state"]
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
require_redraw = True
|
||||
del kwargs["state"]
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
del kwargs["fg_color"]
|
||||
|
||||
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 "hover_color" in kwargs:
|
||||
self.hover_color = kwargs["hover_color"]
|
||||
self.hover_color = kwargs.pop("hover_color")
|
||||
require_redraw = True
|
||||
del kwargs["hover_color"]
|
||||
|
||||
if "text_color" in kwargs:
|
||||
self.text_color = kwargs["text_color"]
|
||||
self.text_color = kwargs.pop("text_color")
|
||||
require_redraw = True
|
||||
del kwargs["text_color"]
|
||||
|
||||
if "border_color" in kwargs:
|
||||
self.border_color = kwargs["border_color"]
|
||||
self.border_color = kwargs.pop("border_color")
|
||||
require_redraw = True
|
||||
del kwargs["border_color"]
|
||||
|
||||
if "border_width" in kwargs:
|
||||
self.border_width = kwargs["border_width"]
|
||||
self.border_width = kwargs.pop("border_width")
|
||||
require_redraw = True
|
||||
del kwargs["border_width"]
|
||||
|
||||
if "command" in kwargs:
|
||||
self.function = kwargs["command"]
|
||||
del kwargs["command"]
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
if "textvariable" in kwargs:
|
||||
self.textvariable = kwargs.pop("textvariable")
|
||||
self.text_label.configure(textvariable=self.textvariable)
|
||||
|
||||
if "variable" in kwargs:
|
||||
if self.variable is not None:
|
||||
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 != "":
|
||||
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
||||
if self.variable.get() == self.value:
|
||||
self.select(from_variable_callback=True)
|
||||
else:
|
||||
self.deselect(from_variable_callback=True)
|
||||
else:
|
||||
self.variable = None
|
||||
self.check_state = True if self.variable.get() == self.value else False
|
||||
require_redraw = True
|
||||
|
||||
del kwargs["variable"]
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def set_cursor(self):
|
||||
if Settings.cursor_manipulation_enabled:
|
||||
@ -250,13 +223,6 @@ class CTkRadioButton(CTkBaseClass):
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(cursor="hand2")
|
||||
|
||||
def set_text(self, text):
|
||||
self.text = text
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(text=self.text)
|
||||
else:
|
||||
sys.stderr.write("ERROR (CTkButton): Cant change text because radiobutton has no text.")
|
||||
|
||||
def on_enter(self, event=0):
|
||||
if self.hover is True and self.state == tkinter.NORMAL:
|
||||
self.canvas.itemconfig("border_parts",
|
||||
@ -287,11 +253,8 @@ class CTkRadioButton(CTkBaseClass):
|
||||
self.check_state = True
|
||||
self.select()
|
||||
|
||||
if self.function is not None:
|
||||
try:
|
||||
self.function()
|
||||
except:
|
||||
pass
|
||||
if self.command is not None:
|
||||
self.command()
|
||||
|
||||
def select(self, from_variable_callback=False):
|
||||
self.check_state = True
|
||||
|
@ -148,17 +148,7 @@ class CTkScrollbar(CTkBaseClass):
|
||||
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"]
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
require_redraw = True
|
||||
@ -196,10 +186,7 @@ class CTkScrollbar(CTkBaseClass):
|
||||
self.set_dimensions(height=kwargs["height"])
|
||||
del kwargs["height"]
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
||||
def on_enter(self, event=0):
|
||||
if self.hover is True:
|
||||
|
@ -72,7 +72,7 @@ class CTkSlider(CTkBaseClass):
|
||||
self.corner_radius = self.button_corner_radius
|
||||
|
||||
# callback and control variables
|
||||
self.callback_function = command
|
||||
self.command = command
|
||||
self.variable: tkinter.Variable = variable
|
||||
self.variable_callback_blocked = False
|
||||
self.variable_callback_name = None
|
||||
@ -205,8 +205,8 @@ class CTkSlider(CTkBaseClass):
|
||||
self.variable.set(round(self.output_value) if isinstance(self.variable, tkinter.IntVar) else self.output_value)
|
||||
self.variable_callback_blocked = False
|
||||
|
||||
if self.callback_function is not None:
|
||||
self.callback_function(self.output_value)
|
||||
if self.command is not None:
|
||||
self.command(self.output_value)
|
||||
|
||||
def on_enter(self, event=0):
|
||||
if self.state == "normal":
|
||||
@ -249,9 +249,6 @@ class CTkSlider(CTkBaseClass):
|
||||
|
||||
self.draw(no_color_updates=False)
|
||||
|
||||
# if self.callback_function is not None and not from_variable_callback:
|
||||
# self.callback_function(self.output_value)
|
||||
|
||||
if self.variable is not None and not from_variable_callback:
|
||||
self.variable_callback_blocked = True
|
||||
self.variable.set(round(self.output_value) if isinstance(self.variable, tkinter.IntVar) else self.output_value)
|
||||
@ -261,9 +258,7 @@ class CTkSlider(CTkBaseClass):
|
||||
if not self.variable_callback_blocked:
|
||||
self.set(self.variable.get(), from_variable_callback=True)
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs["state"]
|
||||
self.set_cursor()
|
||||
@ -275,14 +270,6 @@ class CTkSlider(CTkBaseClass):
|
||||
require_redraw = True
|
||||
del kwargs["fg_color"]
|
||||
|
||||
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 "progress_color" in kwargs:
|
||||
if kwargs["progress_color"] is None:
|
||||
self.progress_color = self.fg_color
|
||||
@ -324,7 +311,7 @@ class CTkSlider(CTkBaseClass):
|
||||
del kwargs["number_of_steps"]
|
||||
|
||||
if "command" in kwargs:
|
||||
self.callback_function = kwargs["command"]
|
||||
self.command = kwargs["command"]
|
||||
del kwargs["command"]
|
||||
|
||||
if "variable" in kwargs:
|
||||
@ -349,7 +336,4 @@ class CTkSlider(CTkBaseClass):
|
||||
self.set_dimensions(height=kwargs["height"])
|
||||
del kwargs["height"]
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
@ -44,7 +44,7 @@ class CTkSwitch(CTkBaseClass):
|
||||
self.button_color = ThemeManager.theme["color"]["switch_button"] if button_color == "default_theme" else button_color
|
||||
self.button_hover_color = ThemeManager.theme["color"]["switch_button_hover"] if button_hover_color == "default_theme" else button_hover_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_disabled"] if text_color_disabled == "default_theme" else text_color_disabled
|
||||
|
||||
# text
|
||||
self.text = text
|
||||
@ -62,11 +62,8 @@ class CTkSwitch(CTkBaseClass):
|
||||
self.onvalue = onvalue
|
||||
self.offvalue = offvalue
|
||||
|
||||
# if self.corner_radius < self.button_corner_radius:
|
||||
# self.corner_radius = self.button_corner_radius
|
||||
|
||||
# callback and control variables
|
||||
self.callback_function = command
|
||||
self.command = command
|
||||
self.variable: tkinter.Variable = variable
|
||||
self.variable_callback_blocked = False
|
||||
self.variable_callback_name = None
|
||||
@ -94,15 +91,25 @@ class CTkSwitch(CTkBaseClass):
|
||||
self.canvas.bind("<Leave>", self.on_leave)
|
||||
self.canvas.bind("<Button-1>", self.toggle)
|
||||
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
bd=0,
|
||||
text=self.text,
|
||||
justify=tkinter.LEFT,
|
||||
font=self.apply_font_scaling(self.text_font),
|
||||
textvariable=self.textvariable)
|
||||
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
||||
self.text_label["anchor"] = "w"
|
||||
|
||||
self.text_label.bind("<Enter>", self.on_enter)
|
||||
self.text_label.bind("<Leave>", self.on_leave)
|
||||
self.text_label.bind("<Button-1>", self.toggle)
|
||||
|
||||
self.draw() # initial draw
|
||||
self.set_cursor()
|
||||
|
||||
if self.variable is not None:
|
||||
if self.variable is not None and self.variable != "":
|
||||
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
||||
if self.variable.get() == self.onvalue:
|
||||
self.select(from_variable_callback=True)
|
||||
elif self.variable.get() == self.offvalue:
|
||||
self.deselect(from_variable_callback=True)
|
||||
self.check_state = True if self.variable.get() == self.onvalue else False
|
||||
|
||||
def set_scaling(self, *args, **kwargs):
|
||||
super().set_scaling(*args, **kwargs)
|
||||
@ -186,22 +193,6 @@ class CTkSwitch(CTkBaseClass):
|
||||
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))
|
||||
|
||||
if self.text_label is None:
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
bd=0,
|
||||
text=self.text,
|
||||
justify=tkinter.LEFT,
|
||||
font=self.apply_font_scaling(self.text_font))
|
||||
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
||||
self.text_label["anchor"] = "w"
|
||||
|
||||
self.text_label.bind("<Enter>", self.on_enter)
|
||||
self.text_label.bind("<Leave>", self.on_leave)
|
||||
self.text_label.bind("<Button-1>", self.toggle)
|
||||
|
||||
if self.textvariable is not None:
|
||||
self.text_label.configure(textvariable=self.textvariable)
|
||||
|
||||
if self.state == tkinter.DISABLED:
|
||||
self.text_label.configure(fg=(ThemeManager.single_color(self.text_color_disabled, self._appearance_mode)))
|
||||
else:
|
||||
@ -209,13 +200,6 @@ class CTkSwitch(CTkBaseClass):
|
||||
|
||||
self.text_label.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
|
||||
self.set_text(self.text)
|
||||
|
||||
def set_text(self, text):
|
||||
self.text = text
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
def toggle(self, event=None):
|
||||
if self.state is not tkinter.DISABLED:
|
||||
if self.check_state is True:
|
||||
@ -225,8 +209,8 @@ class CTkSwitch(CTkBaseClass):
|
||||
|
||||
self.draw(no_color_updates=True)
|
||||
|
||||
if self.callback_function is not None:
|
||||
self.callback_function()
|
||||
if self.command is not None:
|
||||
self.command()
|
||||
|
||||
if self.variable is not None:
|
||||
self.variable_callback_blocked = True
|
||||
@ -244,8 +228,8 @@ class CTkSwitch(CTkBaseClass):
|
||||
self.variable.set(self.onvalue)
|
||||
self.variable_callback_blocked = False
|
||||
|
||||
if self.callback_function is not None:
|
||||
self.callback_function()
|
||||
if self.command is not None:
|
||||
self.command()
|
||||
|
||||
def deselect(self, from_variable_callback=False):
|
||||
if self.state is not tkinter.DISABLED or from_variable_callback:
|
||||
@ -258,8 +242,8 @@ class CTkSwitch(CTkBaseClass):
|
||||
self.variable.set(self.offvalue)
|
||||
self.variable_callback_blocked = False
|
||||
|
||||
if self.callback_function is not None:
|
||||
self.callback_function()
|
||||
if self.command is not None:
|
||||
self.command()
|
||||
|
||||
def get(self):
|
||||
return self.onvalue if self.check_state is True else self.offvalue
|
||||
@ -283,82 +267,60 @@ class CTkSwitch(CTkBaseClass):
|
||||
elif self.variable.get() == self.offvalue:
|
||||
self.deselect(from_variable_callback=True)
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
require_redraw = False # some attribute changes require a call of self.draw() at the end
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "text" in kwargs:
|
||||
self.text = kwargs.pop("text")
|
||||
self.text_label.configure(text=self.text)
|
||||
|
||||
if "state" in kwargs:
|
||||
self.state = kwargs["state"]
|
||||
self.state = kwargs.pop("state")
|
||||
self.set_cursor()
|
||||
require_redraw = True
|
||||
del kwargs["state"]
|
||||
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs["fg_color"]
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
del kwargs["fg_color"]
|
||||
|
||||
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 "progress_color" in kwargs:
|
||||
if kwargs["progress_color"] is None:
|
||||
new_progress_color = kwargs.pop("progress_color")
|
||||
if new_progress_color is None:
|
||||
self.progress_color = self.fg_color
|
||||
else:
|
||||
self.progress_color = kwargs["progress_color"]
|
||||
self.progress_color = new_progress_color
|
||||
require_redraw = True
|
||||
del kwargs["progress_color"]
|
||||
|
||||
if "button_color" in kwargs:
|
||||
self.button_color = kwargs["button_color"]
|
||||
self.button_color = kwargs.pop("button_color")
|
||||
require_redraw = True
|
||||
del kwargs["button_color"]
|
||||
|
||||
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
|
||||
del kwargs["button_hover_color"]
|
||||
|
||||
if "border_color" in kwargs:
|
||||
self.border_color = kwargs["border_color"]
|
||||
self.border_color = kwargs.pop("border_color")
|
||||
require_redraw = True
|
||||
del kwargs["border_color"]
|
||||
|
||||
if "border_width" in kwargs:
|
||||
self.border_width = kwargs["border_width"]
|
||||
self.border_width = kwargs.pop("border_width")
|
||||
require_redraw = True
|
||||
del kwargs["border_width"]
|
||||
|
||||
if "command" in kwargs:
|
||||
self.callback_function = kwargs["command"]
|
||||
del kwargs["command"]
|
||||
self.command = kwargs.pop("command")
|
||||
|
||||
if "textvariable" in kwargs:
|
||||
self.text_label.configure(textvariable=kwargs["textvariable"])
|
||||
del kwargs["textvariable"]
|
||||
self.textvariable = kwargs.pop("textvariable")
|
||||
self.text_label.configure(textvariable=self.textvariable)
|
||||
|
||||
if "variable" in kwargs:
|
||||
if self.variable is not None:
|
||||
if self.variable is not None and self.variable != "":
|
||||
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 != "":
|
||||
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
||||
if self.variable.get() == self.onvalue:
|
||||
self.select(from_variable_callback=True)
|
||||
elif self.variable.get() == self.offvalue:
|
||||
self.deselect(from_variable_callback=True)
|
||||
else:
|
||||
self.variable = None
|
||||
self.check_state = True if self.variable.get() == self.onvalue else False
|
||||
require_redraw = True
|
||||
|
||||
del kwargs["variable"]
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
super().configure(require_redraw=require_redraw, **kwargs)
|
||||
|
168
customtkinter/widgets/ctk_textbox.py
Normal file
168
customtkinter/widgets/ctk_textbox.py
Normal file
@ -0,0 +1,168 @@
|
||||
import tkinter
|
||||
|
||||
from .ctk_canvas import CTkCanvas
|
||||
from ..theme_manager import ThemeManager
|
||||
from ..draw_engine import DrawEngine
|
||||
from .widget_base_class import CTkBaseClass
|
||||
|
||||
|
||||
class CTkTextbox(CTkBaseClass):
|
||||
def __init__(self, *args,
|
||||
bg_color=None,
|
||||
fg_color="default_theme",
|
||||
border_color="default_theme",
|
||||
border_width="default_theme",
|
||||
corner_radius="default_theme",
|
||||
text_font="default_theme",
|
||||
text_color="default_theme",
|
||||
width=200,
|
||||
height=200,
|
||||
**kwargs):
|
||||
|
||||
# transfer basic functionality (bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
||||
if "master" in kwargs:
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height, master=kwargs.pop("master"))
|
||||
else:
|
||||
super().__init__(*args, bg_color=bg_color, width=width, height=height)
|
||||
|
||||
# color
|
||||
self.fg_color = ThemeManager.theme["color"]["entry"] if fg_color == "default_theme" else fg_color
|
||||
self.border_color = ThemeManager.theme["color"]["frame_border"] if border_color == "default_theme" else border_color
|
||||
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
||||
|
||||
# shape
|
||||
self.corner_radius = ThemeManager.theme["shape"]["frame_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
||||
self.border_width = ThemeManager.theme["shape"]["frame_border_width"] if border_width == "default_theme" else border_width
|
||||
|
||||
# text
|
||||
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
||||
|
||||
# configure 1x1 grid
|
||||
self.grid_rowconfigure(0, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
|
||||
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.grid(row=0, column=0, padx=0, pady=0, rowspan=1, columnspan=1, sticky="nsew")
|
||||
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
self.draw_engine = DrawEngine(self.canvas)
|
||||
|
||||
for arg in ["highlightthickness", "fg", "bg", "font", "width", "height"]:
|
||||
kwargs.pop(arg, None)
|
||||
self.textbox = tkinter.Text(self,
|
||||
fg=ThemeManager.single_color(self.text_color, self._appearance_mode),
|
||||
width=0,
|
||||
height=0,
|
||||
font=self.text_font,
|
||||
highlightthickness=0,
|
||||
insertbackground=ThemeManager.single_color(("black", "white"), self._appearance_mode),
|
||||
bg=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
||||
**kwargs)
|
||||
self.textbox.grid(row=0, column=0, padx=self.corner_radius, pady=self.corner_radius, rowspan=1, columnspan=1, sticky="nsew")
|
||||
|
||||
self.bind('<Configure>', self.update_dimensions_event)
|
||||
self.draw()
|
||||
|
||||
def set_scaling(self, *args, **kwargs):
|
||||
super().set_scaling(*args, **kwargs)
|
||||
|
||||
self.textbox.configure(font=self.apply_font_scaling(self.text_font))
|
||||
self.canvas.configure(width=self.apply_widget_scaling(self._desired_width), height=self.apply_widget_scaling(self._desired_height))
|
||||
self.draw()
|
||||
|
||||
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()
|
||||
|
||||
def draw(self, no_color_updates=False):
|
||||
|
||||
requires_recoloring = self.draw_engine.draw_rounded_rect_with_border(self.apply_widget_scaling(self._current_width),
|
||||
self.apply_widget_scaling(self._current_height),
|
||||
self.apply_widget_scaling(self.corner_radius),
|
||||
self.apply_widget_scaling(self.border_width))
|
||||
|
||||
if no_color_updates is False or requires_recoloring:
|
||||
if self.fg_color is None:
|
||||
self.canvas.itemconfig("inner_parts",
|
||||
fill=ThemeManager.single_color(self.bg_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
else:
|
||||
self.canvas.itemconfig("inner_parts",
|
||||
fill=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self.fg_color, self._appearance_mode))
|
||||
|
||||
self.canvas.itemconfig("border_parts",
|
||||
fill=ThemeManager.single_color(self.border_color, self._appearance_mode),
|
||||
outline=ThemeManager.single_color(self.border_color, self._appearance_mode))
|
||||
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self._appearance_mode))
|
||||
|
||||
self.textbox.configure(fg=ThemeManager.single_color(self.text_color, self._appearance_mode),
|
||||
bg=ThemeManager.single_color(self.fg_color, self._appearance_mode),
|
||||
insertbackground=ThemeManager.single_color(("black", "white"), self._appearance_mode))
|
||||
|
||||
self.canvas.tag_lower("inner_parts")
|
||||
self.canvas.tag_lower("border_parts")
|
||||
|
||||
def yview(self, *args):
|
||||
return self.textbox.yview(*args)
|
||||
|
||||
def xview(self, *args):
|
||||
return self.textbox.xview(*args)
|
||||
|
||||
def insert(self, *args, **kwargs):
|
||||
return self.textbox.insert(*args, **kwargs)
|
||||
|
||||
def focus(self):
|
||||
return self.textbox.focus()
|
||||
|
||||
def tag_add(self, *args, **kwargs):
|
||||
return self.textbox.tag_add(*args, **kwargs)
|
||||
|
||||
def tag_config(self, *args, **kwargs):
|
||||
return self.textbox.tag_config(*args, **kwargs)
|
||||
|
||||
def tag_configure(self, *args, **kwargs):
|
||||
return self.textbox.tag_configure(*args, **kwargs)
|
||||
|
||||
def tag_remove(self, *args, **kwargs):
|
||||
return self.textbox.tag_remove(*args, **kwargs)
|
||||
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
if "fg_color" in kwargs:
|
||||
self.fg_color = kwargs.pop("fg_color")
|
||||
require_redraw = True
|
||||
|
||||
# check if CTk widgets are children of the frame and change their bg_color to new frame fg_color
|
||||
for child in self.winfo_children():
|
||||
if isinstance(child, CTkBaseClass):
|
||||
child.configure(bg_color=self.fg_color)
|
||||
|
||||
if "border_color" in kwargs:
|
||||
self.border_color = kwargs.pop("border_color")
|
||||
require_redraw = True
|
||||
|
||||
if "corner_radius" in kwargs:
|
||||
self.corner_radius = kwargs.pop("corner_radius")
|
||||
require_redraw = True
|
||||
|
||||
if "border_width" in kwargs:
|
||||
self.border_width = kwargs.pop("border_width")
|
||||
require_redraw = True
|
||||
|
||||
if "width" in kwargs:
|
||||
self.set_dimensions(width=kwargs.pop("width"))
|
||||
|
||||
if "height" in kwargs:
|
||||
self.set_dimensions(height=kwargs.pop("height"))
|
||||
|
||||
if "bg_color" in kwargs:
|
||||
super().configure(bg_color=kwargs.pop("bg_color"), require_redraw=require_redraw)
|
||||
else:
|
||||
super().configure(require_redraw=require_redraw)
|
||||
|
||||
self.textbox.configure(**kwargs)
|
@ -42,6 +42,8 @@ class DropdownMenu(tkinter.Menu):
|
||||
self.add_menu_commands()
|
||||
|
||||
def configure_menu_for_platforms(self):
|
||||
""" apply platform specific appearance attributes """
|
||||
|
||||
if sys.platform == "darwin":
|
||||
self.configure(tearoff=False,
|
||||
font=self.apply_font_scaling(self.text_font))
|
||||
@ -98,29 +100,24 @@ class DropdownMenu(tkinter.Menu):
|
||||
|
||||
def configure(self, **kwargs):
|
||||
if "values" in kwargs:
|
||||
self.values = kwargs["values"]
|
||||
del kwargs["values"]
|
||||
self.values = kwargs.pop("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.fg_color = kwargs.pop("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.hover_color = kwargs.pop("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.text_color = kwargs.pop("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.text_font = kwargs.pop("text_font")
|
||||
self.configure(font=self.apply_font_scaling(self.text_font))
|
||||
|
||||
super().configure(**kwargs)
|
||||
|
@ -17,7 +17,7 @@ from ..theme_manager import ThemeManager
|
||||
|
||||
|
||||
class CTkBaseClass(tkinter.Frame):
|
||||
""" Base class of every Ctk widget, handles the dimensions, bg_color,
|
||||
""" Base class of every CTk widget, handles the dimensions, bg_color,
|
||||
appearance_mode changes, scaling, bg changes of master if master is not a CTk widget """
|
||||
|
||||
def __init__(self,
|
||||
@ -26,6 +26,7 @@ class CTkBaseClass(tkinter.Frame):
|
||||
width: int,
|
||||
height: int,
|
||||
**kwargs):
|
||||
|
||||
super().__init__(*args, width=width, height=height, **kwargs) # set desired size of underlying tkinter.Frame
|
||||
|
||||
# dimensions
|
||||
@ -116,29 +117,24 @@ class CTkBaseClass(tkinter.Frame):
|
||||
|
||||
return scaled_kwargs
|
||||
|
||||
def config(self, *args, **kwargs):
|
||||
self.configure(*args, **kwargs)
|
||||
|
||||
def configure(self, *args, **kwargs):
|
||||
def configure(self, require_redraw=False, **kwargs):
|
||||
""" basic configure with bg_color support, to be overridden """
|
||||
|
||||
require_redraw = False
|
||||
|
||||
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()
|
||||
else:
|
||||
self.bg_color = kwargs["bg_color"]
|
||||
self.bg_color = new_bg_color
|
||||
require_redraw = True
|
||||
del kwargs["bg_color"]
|
||||
|
||||
super().configure(*args, **kwargs)
|
||||
super().configure(**kwargs)
|
||||
|
||||
if require_redraw:
|
||||
self.draw()
|
||||
|
||||
def update_dimensions_event(self, event):
|
||||
# only redraw if dimensions changed (for performance)
|
||||
# only redraw if dimensions changed (for performance), independent of scaling
|
||||
if round(self._current_width) != round(event.width / self._widget_scaling) or round(self._current_height) != round(event.height / self._widget_scaling):
|
||||
self._current_width = (event.width / self._widget_scaling) # adjust current size according to new size given by event
|
||||
self._current_height = (event.height / self._widget_scaling) # _current_width and _current_height are independent of the scale
|
||||
@ -151,7 +147,7 @@ class CTkBaseClass(tkinter.Frame):
|
||||
if master_widget is None:
|
||||
master_widget = self.master
|
||||
|
||||
if isinstance(master_widget, CTkBaseClass) and hasattr(master_widget, "fg_color"): # master is CTkFrame
|
||||
if isinstance(master_widget, (CTkBaseClass, CTk, CTkToplevel)) and hasattr(master_widget, "fg_color"):
|
||||
if master_widget.fg_color is not None:
|
||||
return master_widget.fg_color
|
||||
|
||||
@ -159,7 +155,7 @@ class CTkBaseClass(tkinter.Frame):
|
||||
elif hasattr(master_widget.master, "master"):
|
||||
return self.detect_color_of_master(self.master.master)
|
||||
|
||||
elif isinstance(master_widget, (ttk.Frame, ttk.LabelFrame, ttk.Notebook)): # master is ttk widget
|
||||
elif isinstance(master_widget, (ttk.Frame, ttk.LabelFrame, ttk.Notebook, ttk.Label)): # master is ttk widget
|
||||
try:
|
||||
ttk_style = ttk.Style()
|
||||
return ttk_style.lookup(master_widget.winfo_class(), 'background')
|
||||
@ -178,11 +174,6 @@ class CTkBaseClass(tkinter.Frame):
|
||||
elif mode_string.lower() == "light":
|
||||
self._appearance_mode = 0
|
||||
|
||||
if isinstance(self.master, (CTkBaseClass, CTk)) and hasattr(self.master, "fg_color"):
|
||||
self.bg_color = self.master.fg_color
|
||||
else:
|
||||
self.bg_color = self.master.cget("bg")
|
||||
|
||||
self.draw()
|
||||
|
||||
def set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling):
|
||||
|
@ -102,8 +102,12 @@ class CTkInputDialog:
|
||||
self.running = True
|
||||
|
||||
while self.running:
|
||||
self.top.update()
|
||||
time.sleep(0.01)
|
||||
try:
|
||||
self.top.update()
|
||||
except Exception:
|
||||
return self.user_input
|
||||
finally:
|
||||
time.sleep(0.01)
|
||||
|
||||
time.sleep(0.05)
|
||||
self.top.destroy()
|
||||
|
@ -28,6 +28,7 @@ progressbar_1.pack(pady=12, padx=10)
|
||||
|
||||
button_1 = customtkinter.CTkButton(master=frame_1, command=button_callback)
|
||||
button_1.pack(pady=12, padx=10)
|
||||
button_1.configure(state='disabled')
|
||||
|
||||
slider_1 = customtkinter.CTkSlider(master=frame_1, command=slider_callback, from_=0, to=1)
|
||||
slider_1.pack(pady=12, padx=10)
|
||||
|
@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
||||
github_url = "https://github.com/TomSchimansky/CustomTkinter"
|
||||
|
||||
[tool.tbump.version]
|
||||
current = "4.5.0"
|
||||
current = "4.5.5"
|
||||
|
||||
# Example of a semver regexp.
|
||||
# Make sure this matches current_version before
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = customtkinter
|
||||
version = 4.5.0
|
||||
version = 4.5.5
|
||||
description = Create modern looking GUIs with Python
|
||||
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
|
||||
|
148
test/manual_integration_tests/complex_example_new.py
Normal file
148
test/manual_integration_tests/complex_example_new.py
Normal file
@ -0,0 +1,148 @@
|
||||
import tkinter
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
|
||||
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
|
||||
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.title("CustomTkinter complex_example.py")
|
||||
self.geometry(f"{920}x{500}")
|
||||
self.protocol("WM_DELETE_WINDOW", self.on_closing) # call .on_closing() when app gets closed
|
||||
|
||||
# configure grid layout (4x4)
|
||||
self.grid_columnconfigure(1, weight=1)
|
||||
self.grid_columnconfigure((2, 3), weight=0, minsize=200)
|
||||
self.grid_rowconfigure((0, 1, 2), weight=1)
|
||||
|
||||
# create sidebar frame with widgets
|
||||
self.sidebar_frame = customtkinter.CTkFrame(self, width=140)
|
||||
self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsew")
|
||||
self.sidebar_frame.grid_rowconfigure(4, weight=1)
|
||||
self.logo_label = customtkinter.CTkLabel(self.sidebar_frame, text="CustomTkinter", text_font=("Roboto", -16))
|
||||
self.logo_label.grid(row=0, column=0, padx=20, pady=(20, 10))
|
||||
self.sidebar_button_1 = customtkinter.CTkButton(self.sidebar_frame, command=self.sidebar_button_callback)
|
||||
self.sidebar_button_1.grid(row=1, column=0, padx=20, pady=10)
|
||||
self.sidebar_button_2 = customtkinter.CTkButton(self.sidebar_frame, command=self.sidebar_button_callback)
|
||||
self.sidebar_button_2.grid(row=2, column=0, padx=20, pady=10)
|
||||
self.sidebar_button_3 = customtkinter.CTkButton(self.sidebar_frame, command=self.sidebar_button_callback)
|
||||
self.sidebar_button_3.grid(row=3, column=0, padx=20, pady=10)
|
||||
self.appearance_mode_label = customtkinter.CTkLabel(self.sidebar_frame, text="Appearance Mode:", anchor="w")
|
||||
self.appearance_mode_label.grid(row=5, column=0, padx=20, pady=(10, 0))
|
||||
self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["Light", "Dark", "System"],
|
||||
command=self.change_appearance_mode)
|
||||
self.appearance_mode_optionemenu.grid(row=6, column=0, padx=20, pady=(10, 10))
|
||||
self.scaling_label = customtkinter.CTkLabel(self.sidebar_frame, text="Widget Scaling:", anchor="w")
|
||||
self.scaling_label.grid(row=7, column=0, padx=20, pady=(10, 0))
|
||||
self.scaling_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["90%", "100%", "110%"],
|
||||
command=self.change_scaling)
|
||||
self.scaling_optionemenu.grid(row=8, column=0, padx=20, pady=(10, 20))
|
||||
|
||||
# create main entry and button
|
||||
self.entry = customtkinter.CTkEntry(self, placeholder_text="CTkEntry")
|
||||
self.entry.grid(row=3, column=1, columnspan=2, padx=(20, 10), pady=(10, 20), sticky="nsew")
|
||||
|
||||
self.main_button_1 = customtkinter.CTkButton(self, fg_color=None, border_width=2)
|
||||
self.main_button_1.grid(row=3, column=3, padx=(10, 20), pady=(10, 20), sticky="nsew")
|
||||
|
||||
self.textbox = customtkinter.CTkTextbox(self)
|
||||
self.textbox.grid(row=0, column=1, padx=(20, 10), pady=(20, 10), sticky="nsew")
|
||||
|
||||
# create radiobutton frame
|
||||
self.radiobutton_frame = customtkinter.CTkFrame(self)
|
||||
self.radiobutton_frame.grid(row=0, column=3, padx=(10, 20), pady=(20, 10), sticky="nsew")
|
||||
self.radio_var = tkinter.IntVar(value=0)
|
||||
self.label_radio_group = customtkinter.CTkLabel(master=self.radiobutton_frame, text="CTkRadioButton Group:")
|
||||
self.label_radio_group.grid(row=0, column=2, columnspan=1, padx=10, pady=10, sticky="")
|
||||
self.radio_button_1 = customtkinter.CTkRadioButton(master=self.radiobutton_frame, variable=self.radio_var, value=0)
|
||||
self.radio_button_1.grid(row=1, column=2, pady=10, padx=20, sticky="n")
|
||||
self.radio_button_2 = customtkinter.CTkRadioButton(master=self.radiobutton_frame, variable=self.radio_var, value=1)
|
||||
self.radio_button_2.grid(row=2, column=2, pady=10, padx=20, sticky="n")
|
||||
self.radio_button_3 = customtkinter.CTkRadioButton(master=self.radiobutton_frame, variable=self.radio_var, value=2)
|
||||
self.radio_button_3.grid(row=3, column=2, pady=10, padx=20, sticky="n")
|
||||
|
||||
# create optionemnu and combobox frame
|
||||
self.optionemnu_combobox_frame = customtkinter.CTkFrame(self)
|
||||
self.optionemnu_combobox_frame.grid(row=0, column=2, padx=(10, 10), pady=(20, 10), sticky="nsew")
|
||||
self.optionmenu_1 = customtkinter.CTkOptionMenu(self.optionemnu_combobox_frame,
|
||||
dynamic_resizing=False,
|
||||
values=["Value 1", "Value 2", "Value Long Long Long"])
|
||||
self.optionmenu_1.grid(row=0, column=0, padx=20, pady=(20, 10), sticky="ew")
|
||||
self.combobox_1 = customtkinter.CTkComboBox(self.optionemnu_combobox_frame,
|
||||
values=["Value 1", "Value 2", "Value Long....."])
|
||||
self.combobox_1.grid(row=1, column=0, padx=20, pady=(10, 10), sticky="ew")
|
||||
self.string_input_button = customtkinter.CTkButton(self.optionemnu_combobox_frame, text="Open CTkInputDialog",
|
||||
command=self.open_input_dialog)
|
||||
self.string_input_button.grid(row=2, column=0, padx=20, pady=(10, 10), sticky="ew")
|
||||
|
||||
# create checkbox and switch frame
|
||||
self.checkbox_slider_frame = customtkinter.CTkFrame(self)
|
||||
self.checkbox_slider_frame.grid(row=1, column=3, padx=(10, 20), pady=(10, 10), sticky="nsew")
|
||||
self.checkbox_1 = customtkinter.CTkCheckBox(master=self.checkbox_slider_frame)
|
||||
self.checkbox_1.grid(row=1, column=0, pady=(20, 10), padx=20, sticky="n")
|
||||
self.checkbox_2 = customtkinter.CTkCheckBox(master=self.checkbox_slider_frame)
|
||||
self.checkbox_2.grid(row=2, column=0, pady=10, padx=20, sticky="n")
|
||||
self.switch_1 = customtkinter.CTkSwitch(master=self.checkbox_slider_frame)
|
||||
self.switch_1.grid(row=3, column=0, pady=10, padx=20, sticky="n")
|
||||
self.switch_2 = customtkinter.CTkSwitch(master=self.checkbox_slider_frame)
|
||||
self.switch_2.grid(row=4, column=0, pady=(10, 20), padx=20, sticky="n")
|
||||
|
||||
# create slider and progressbar frame
|
||||
self.slider_progressbar_frame = customtkinter.CTkFrame(self, fg_color=None)
|
||||
self.slider_progressbar_frame.grid(row=1, column=1, columnspan=2, padx=(20, 10), pady=(10, 10), sticky="nsew")
|
||||
self.slider_progressbar_frame.grid_columnconfigure(0, weight=1)
|
||||
self.slider_progressbar_frame.grid_rowconfigure(3, weight=1)
|
||||
self.progressbar_1 = customtkinter.CTkProgressBar(self.slider_progressbar_frame)
|
||||
self.progressbar_1.grid(row=0, column=0, padx=(20, 10), pady=(10, 10), sticky="ew")
|
||||
self.slider_1 = customtkinter.CTkSlider(self.slider_progressbar_frame)
|
||||
self.slider_1.grid(row=1, column=0, padx=(20, 10), pady=(10, 10), sticky="ew")
|
||||
self.slider_2 = customtkinter.CTkSlider(self.slider_progressbar_frame, from_=0, to=4, number_of_steps=4)
|
||||
self.slider_2.grid(row=2, column=0, padx=(20, 10), pady=(10, 10), sticky="ew")
|
||||
self.slider_3 = customtkinter.CTkSlider(self.slider_progressbar_frame, orient="vertical")
|
||||
self.slider_3.grid(row=0, column=1, rowspan=4, padx=(10, 10), pady=(10, 10), sticky="ns")
|
||||
self.progressbar_2 = customtkinter.CTkProgressBar(self.slider_progressbar_frame, orient="vertical")
|
||||
self.progressbar_2.grid(row=0, column=2, rowspan=4, padx=(10, 20), pady=(10, 10), sticky="ns")
|
||||
|
||||
# set default values
|
||||
self.sidebar_button_3.configure(state="disabled", text="Disabled CTkButton")
|
||||
self.checkbox_2.configure(state="disabled")
|
||||
self.switch_2.configure(state="disabled")
|
||||
self.checkbox_1.select()
|
||||
self.switch_1.select()
|
||||
self.radio_button_3.configure(state="disabled")
|
||||
self.appearance_mode_optionemenu.set("Dark")
|
||||
self.scaling_optionemenu.set("100%")
|
||||
self.optionmenu_1.set("CTkOptionmenu")
|
||||
self.combobox_1.set("CTkComboBox")
|
||||
self.textbox.insert("1.0",
|
||||
"CTkTextbox\n\nLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.", )
|
||||
#self.textbox.tag_add("headline", "1.0", "1.end")
|
||||
#self.textbox.tag_config("headline", foreground="red")
|
||||
|
||||
def open_input_dialog(self):
|
||||
dialog = customtkinter.CTkInputDialog(master=None, text="Type in a number:", title="CTkInputDialog")
|
||||
print("CTkInputDialog:", dialog.get_input())
|
||||
|
||||
def change_appearance_mode(self, new_appearance_mode: str):
|
||||
customtkinter.set_appearance_mode(new_appearance_mode)
|
||||
|
||||
def change_scaling(self, new_scaling: str):
|
||||
new_scaling_float = int(new_scaling.replace("%", "")) / 100
|
||||
customtkinter.set_spacing_scaling(new_scaling_float)
|
||||
customtkinter.set_widget_scaling(new_scaling_float)
|
||||
|
||||
def sidebar_button_callback(self):
|
||||
print("sidebar_button click")
|
||||
|
||||
def on_closing(self, event=0):
|
||||
self.destroy()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.mainloop()
|
@ -4,7 +4,7 @@ import customtkinter
|
||||
|
||||
app = customtkinter.CTk()
|
||||
app.title('Test OptionMenu ComboBox.py')
|
||||
app.geometry('400x300')
|
||||
app.geometry('400x500')
|
||||
|
||||
|
||||
def select_callback(choice):
|
||||
@ -33,4 +33,12 @@ 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)
|
||||
|
||||
def set_new_scaling(scaling):
|
||||
customtkinter.set_spacing_scaling(scaling)
|
||||
customtkinter.set_window_scaling(scaling)
|
||||
customtkinter.set_widget_scaling(scaling)
|
||||
|
||||
scaling_slider = customtkinter.CTkSlider(app, command=set_new_scaling, from_=0, to=2)
|
||||
scaling_slider.pack(pady=20, padx=10)
|
||||
|
||||
app.mainloop()
|
||||
|
54
test/manual_integration_tests/test_textbox.py
Normal file
54
test/manual_integration_tests/test_textbox.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 = customtkinter.CTkTextbox(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 = customtkinter.CTkTextbox(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 = customtkinter.CTkTextbox(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()
|
@ -5,15 +5,20 @@ TEST_CONFIGURE = True
|
||||
TEST_REMOVING = False
|
||||
|
||||
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
|
||||
app.geometry("400x800")
|
||||
app.geometry("400x900")
|
||||
app.title("Tkinter Variable Test")
|
||||
|
||||
def checkbox_event():
|
||||
print("checkbox_event")
|
||||
|
||||
txt_var = tkinter.StringVar(value="")
|
||||
entry_1 = customtkinter.CTkEntry(app, width=200, textvariable=txt_var)
|
||||
entry_1 = customtkinter.CTkEntry(app, width=200, textvariable=txt_var, placeholder_text="placeholder")
|
||||
entry_1.pack(pady=15)
|
||||
txt_var.set("new text test")
|
||||
if TEST_CONFIGURE: entry_1.configure(textvariable=txt_var)
|
||||
if TEST_REMOVING: entry_1.configure(textvariable="")
|
||||
#entry_1.delete(0, "end")
|
||||
#entry_1.insert(0, "sadsad")
|
||||
|
||||
label_1 = customtkinter.CTkLabel(app, width=200, textvariable=txt_var)
|
||||
label_1.pack(pady=15)
|
||||
@ -46,11 +51,13 @@ if TEST_CONFIGURE: progress_1.configure(variable=int_var)
|
||||
if TEST_REMOVING: progress_1.configure(variable="")
|
||||
|
||||
check_var = tkinter.StringVar(value="on")
|
||||
check_1 = customtkinter.CTkCheckBox(app, text="check 1", variable=check_var, onvalue="on", offvalue="off")
|
||||
check_1 = customtkinter.CTkCheckBox(app, text="check 1", variable=check_var, onvalue="on", offvalue="off", textvariable=txt_var,
|
||||
command=checkbox_event)
|
||||
check_1.pack(pady=15)
|
||||
if TEST_CONFIGURE: check_1.configure(variable=check_var)
|
||||
if TEST_REMOVING: check_1.configure(variable="")
|
||||
print("check_1", check_1.get())
|
||||
|
||||
print("check 1 created")
|
||||
|
||||
check_2 = customtkinter.CTkCheckBox(app, text="check 2", variable=check_var, onvalue="on", offvalue="off")
|
||||
check_2.pack(pady=15)
|
||||
@ -67,8 +74,8 @@ def switch_event():
|
||||
s_var = tkinter.StringVar(value="on")
|
||||
switch_1 = customtkinter.CTkSwitch(master=app, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off", command=switch_event)
|
||||
switch_1.pack(pady=20, padx=10)
|
||||
switch_1 = customtkinter.CTkSwitch(master=app, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off")
|
||||
switch_1.pack(pady=20, padx=10)
|
||||
switch_2 = customtkinter.CTkSwitch(master=app, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off")
|
||||
switch_2.pack(pady=20, padx=10)
|
||||
|
||||
optionmenu_var = tkinter.StringVar(value="test")
|
||||
optionmenu_1 = customtkinter.CTkOptionMenu(master=app, variable=optionmenu_var, values=["Option 1", "Option 2", "Option 3"])
|
||||
@ -77,4 +84,7 @@ combobox_1 = customtkinter.CTkComboBox(master=app, values=["Option 1", "Option 2
|
||||
combobox_1.pack(pady=20, padx=10)
|
||||
combobox_1.configure(variable=optionmenu_var)
|
||||
|
||||
radio_1 = customtkinter.CTkRadioButton(app, textvariable=txt_var)
|
||||
radio_1.pack(pady=20, padx=10)
|
||||
|
||||
app.mainloop()
|
||||
|
27
test/manual_integration_tests/text_entry_placeholder.py
Normal file
27
test/manual_integration_tests/text_entry_placeholder.py
Normal file
@ -0,0 +1,27 @@
|
||||
import customtkinter
|
||||
|
||||
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
|
||||
app.geometry("400x400")
|
||||
app.title("test_entry_placeholder.py")
|
||||
|
||||
str_var = customtkinter.StringVar(value="test")
|
||||
|
||||
entry_1 = customtkinter.CTkEntry(app, placeholder_text="placeholder", textvariable=str_var)
|
||||
entry_1.pack(pady=20)
|
||||
|
||||
entry_2 = customtkinter.CTkEntry(app, placeholder_text="placeholder", textvariable=str_var)
|
||||
entry_2.pack(pady=20)
|
||||
entry_2.insert(0, "sdfjk ")
|
||||
entry_2.delete(0, 2)
|
||||
|
||||
entry_3 = customtkinter.CTkEntry(app, placeholder_text="placeholder")
|
||||
entry_3.pack(pady=(40, 20))
|
||||
entry_3.insert(0, "sdfjk")
|
||||
entry_3.delete(0, "end")
|
||||
|
||||
entry_4 = customtkinter.CTkEntry(app, placeholder_text="password", show="*")
|
||||
entry_4.pack(pady=(20, 20))
|
||||
entry_4.insert(0, "sdfjk")
|
||||
entry_4.delete(0, 2)
|
||||
|
||||
app.mainloop()
|
Reference in New Issue
Block a user