16 Commits

38 changed files with 286 additions and 241 deletions

View File

@ -1,6 +1,17 @@
# Changelog
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/).
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).
*This document is a WIP.*
## [4.0.0] - 2022-05-22
### Added
- This changelog file
- Adopted semantic versioning
- Added HighDPI scaling to all widgets and geometry managers (place, pack, grid)
- Restructured CTkSettings and renamed a few manager classes
### Changed
### Removed
- A few unnecessary tests

View File

@ -41,17 +41,17 @@ import customtkinter
customtkinter.set_appearance_mode("System") # Modes: system (default), light, dark
customtkinter.set_default_color_theme("blue") # Themes: blue (default), dark-blue, green
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window
root_tk.geometry("400x240")
app = customtkinter.CTk() # create CTk window like you do with the Tk window
app.geometry("400x240")
def button_function():
print("button pressed")
# Use CTkButton instead of tkinter Button
button = customtkinter.CTkButton(master=root_tk, text="CTkButton", command=button_function)
button = customtkinter.CTkButton(master=app, text="CTkButton", command=button_function)
button.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
root_tk.mainloop()
app.mainloop()
```
which gives the following (macOS dark mode on):

View File

View File

@ -1,7 +1,8 @@
__version__ = "4.0.0"
__version__ = "4.0.4"
import os
import sys
from tkinter.constants import *
# import manager classes
from .settings import Settings

View File

@ -19,7 +19,7 @@ except Exception:
class AppearanceModeTracker:
callback_list = []
root_tk_list = []
app_list = []
update_loop_running = False
update_loop_interval = 500 # milliseconds
@ -40,12 +40,12 @@ class AppearanceModeTracker:
cls.callback_list.append(callback)
if widget is not None:
root_tk = cls.get_tk_root_of_widget(widget)
if root_tk not in cls.root_tk_list:
cls.root_tk_list.append(root_tk)
app = cls.get_tk_root_of_widget(widget)
if app not in cls.app_list:
cls.app_list.append(app)
if not cls.update_loop_running:
root_tk.after(500, cls.update)
app.after(500, cls.update)
cls.update_loop_running = True
@classmethod
@ -97,9 +97,9 @@ class AppearanceModeTracker:
cls.update_callbacks()
# find an existing tkinter.Tk object for the next call of .after()
for root_tk in cls.root_tk_list:
for app in cls.app_list:
try:
root_tk.after(cls.update_loop_interval, cls.update)
app.after(cls.update_loop_interval, cls.update)
return
except Exception:
continue

View File

@ -51,7 +51,7 @@ class FontManager:
return cls.windows_load_font(font_path, private=True, enumerable=False)
# Linux
elif sys.platform.startswith("win"):
elif sys.platform.startswith("linux"):
try:
shutil.copy(font_path, os.path.expanduser("~/.fonts/"))
return True

View File

@ -168,9 +168,9 @@ class ScalingTracker:
cls.update_scaling_callbacks_for_window(window)
# find an existing tkinter object for the next call of .after()
for root_tk in cls.window_widgets_dict.keys():
for app in cls.window_widgets_dict.keys():
try:
root_tk.after(cls.update_loop_interval, cls.check_dpi_scaling)
app.after(cls.update_loop_interval, cls.check_dpi_scaling)
return
except Exception:
continue

View File

@ -2,7 +2,6 @@ import tkinter
from .ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..settings import Settings
from ..draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
@ -20,6 +19,7 @@ class CTkEntry(CTkBaseClass):
border_color="default_theme",
width=120,
height=30,
state=tkinter.NORMAL,
**kwargs):
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
@ -42,6 +42,8 @@ class CTkEntry(CTkBaseClass):
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
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
@ -57,6 +59,7 @@ class CTkEntry(CTkBaseClass):
width=1,
highlightthickness=0,
font=self.apply_font_scaling(self.text_font),
state=self.state,
**kwargs)
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))
@ -138,6 +141,11 @@ class CTkEntry(CTkBaseClass):
def configure(self, *args, **kwargs):
require_redraw = False # some attribute changes require a call of self.draw() at the end
if "state" in kwargs:
self.state = kwargs["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()

View File

@ -115,11 +115,21 @@ class CTkFrame(CTkBaseClass):
del kwargs["bg_color"]
if "border_color" in kwargs:
self.border_color = kwargs["border_color"]
require_redraw = True
del kwargs["border_color"]
if "corner_radius" in kwargs:
self.corner_radius = kwargs["corner_radius"]
require_redraw = True
del kwargs["corner_radius"]
if "border_width" in kwargs:
self.border_width = kwargs["border_width"]
require_redraw = True
del kwargs["border_width"]
super().configure(*args, **kwargs)
if require_redraw:

View File

@ -2,7 +2,6 @@ import tkinter
from .ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager
from ..settings import Settings
from ..draw_engine import DrawEngine
from .widget_base_class import CTkBaseClass
@ -68,6 +67,8 @@ class CTkLabel(CTkBaseClass):
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))
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),

View File

@ -13,6 +13,7 @@ class CTkSwitch(CTkBaseClass):
text="CTkSwitch",
text_font="default_theme",
text_color="default_theme",
text_color_disabled="default_theme",
bg_color=None,
border_color=None,
fg_color="default_theme",
@ -30,6 +31,7 @@ class CTkSwitch(CTkBaseClass):
offvalue=0,
variable=None,
textvariable=None,
state=tkinter.NORMAL,
**kwargs):
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
@ -42,6 +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
# text
self.text = text
@ -55,6 +58,7 @@ class CTkSwitch(CTkBaseClass):
self.button_length = ThemeManager.theme["shape"]["switch_button_length"] if button_length == "default_theme" else button_length
self.hover_state = False
self.check_state = False # True if switch is activated
self.state = state
self.onvalue = onvalue
self.offvalue = offvalue
@ -119,10 +123,16 @@ class CTkSwitch(CTkBaseClass):
def set_cursor(self):
if Settings.cursor_manipulation_enabled:
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
self.canvas.configure(cursor="pointinghand")
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
self.canvas.configure(cursor="hand2")
if self.state == tkinter.DISABLED:
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
self.canvas.configure(cursor="arrow")
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
self.canvas.configure(cursor="arrow")
else:
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
self.canvas.configure(cursor="pointinghand")
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
self.canvas.configure(cursor="hand2")
def draw(self, no_color_updates=False):
@ -178,7 +188,11 @@ class CTkSwitch(CTkBaseClass):
if self.textvariable is not None:
self.text_label.configure(textvariable=self.textvariable)
self.text_label.configure(fg=ThemeManager.single_color(self.text_color, self.appearance_mode))
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)
@ -189,54 +203,59 @@ class CTkSwitch(CTkBaseClass):
self.text_label.configure(text=self.text)
def toggle(self, event=None):
if self.check_state is True:
self.check_state = False
else:
self.check_state = True
if self.state is not tkinter.DISABLED:
if self.check_state is True:
self.check_state = False
else:
self.check_state = True
self.draw(no_color_updates=True)
self.draw(no_color_updates=True)
if self.callback_function is not None:
self.callback_function()
if self.callback_function is not None:
self.callback_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.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
def select(self, from_variable_callback=False):
self.check_state = True
if self.state is not tkinter.DISABLED or from_variable_callback:
self.check_state = True
self.draw(no_color_updates=True)
self.draw(no_color_updates=True)
if self.callback_function is not None:
self.callback_function()
if self.callback_function is not None:
self.callback_function()
if self.variable is not None and not from_variable_callback:
self.variable_callback_blocked = True
self.variable.set(self.onvalue)
self.variable_callback_blocked = False
if self.variable is not None and not from_variable_callback:
self.variable_callback_blocked = True
self.variable.set(self.onvalue)
self.variable_callback_blocked = False
def deselect(self, from_variable_callback=False):
self.check_state = False
if self.state is not tkinter.DISABLED or from_variable_callback:
self.check_state = False
self.draw(no_color_updates=True)
self.draw(no_color_updates=True)
if self.callback_function is not None:
self.callback_function()
if self.callback_function is not None:
self.callback_function()
if self.variable is not None and not from_variable_callback:
self.variable_callback_blocked = True
self.variable.set(self.offvalue)
self.variable_callback_blocked = False
if self.variable is not None and not from_variable_callback:
self.variable_callback_blocked = True
self.variable.set(self.offvalue)
self.variable_callback_blocked = False
def get(self):
return self.onvalue if self.check_state is True else self.offvalue
def on_enter(self, event=0):
self.hover_state = True
self.canvas.itemconfig("slider_parts", fill=ThemeManager.single_color(self.button_hover_color, self.appearance_mode),
outline=ThemeManager.single_color(self.button_hover_color, self.appearance_mode))
if self.state is not tkinter.DISABLED:
self.canvas.itemconfig("slider_parts", fill=ThemeManager.single_color(self.button_hover_color, self.appearance_mode),
outline=ThemeManager.single_color(self.button_hover_color, self.appearance_mode))
def on_leave(self, event=0):
self.hover_state = False
@ -253,6 +272,12 @@ class CTkSwitch(CTkBaseClass):
def configure(self, *args, **kwargs):
require_redraw = False # some attribute changes require a call of self.draw() at the end
if "state" in kwargs:
self.state = kwargs["state"]
self.set_cursor()
require_redraw = True
del kwargs["state"]
if "fg_color" in kwargs:
self.fg_color = kwargs["fg_color"]
require_redraw = True

View File

@ -2,7 +2,12 @@ import tkinter
import tkinter.ttk as ttk
import copy
import re
from typing import Callable, Union, TypedDict
from typing import Callable, Union
try:
from typing import TypedDict
except ImportError:
from typing_extensions import TypedDict
from ..windows.ctk_tk import CTk
from ..windows.ctk_toplevel import CTkToplevel
@ -130,22 +135,30 @@ class CTkBaseClass(tkinter.Frame):
self.draw(no_color_updates=True) # faster drawing without color changes
def detect_color_of_master(self):
def detect_color_of_master(self, master_widget=None):
""" detect color of self.master widget to set correct bg_color """
if isinstance(self.master, CTkBaseClass) and hasattr(self.master, "fg_color"): # master is CTkFrame
return self.master.fg_color
if master_widget is None:
master_widget = self.master
elif isinstance(self.master, (ttk.Frame, ttk.LabelFrame, ttk.Notebook)): # master is ttk widget
if isinstance(master_widget, CTkBaseClass) and hasattr(master_widget, "fg_color"): # master is CTkFrame
if master_widget.fg_color is not None:
return master_widget.fg_color
# if fg_color of master is None, try to retrieve fg_color from master of master
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
try:
ttk_style = ttk.Style()
return ttk_style.lookup(self.master.winfo_class(), 'background')
return ttk_style.lookup(master_widget.winfo_class(), 'background')
except Exception:
return "#FFFFFF", "#000000"
else: # master is normal tkinter widget
try:
return self.master.cget("bg") # try to get bg color by .cget() method
return master_widget.cget("bg") # try to get bg color by .cget() method
except Exception:
return "#FFFFFF", "#000000"

View File

@ -69,7 +69,6 @@ class CTk(tkinter.Tk):
if self.current_width != round(detected_width / self.window_scaling) or self.current_height != round(detected_height / self.window_scaling):
self.current_width = round(detected_width / self.window_scaling) # adjust current size according to new size given by event
self.current_height = round(detected_height / self.window_scaling) # current_width and current_height are independent of the scale
print("update_dimensions_event:", self.current_width)
def set_scaling(self, new_widget_scaling, new_spacing_scaling, new_window_scaling):
self.window_scaling = new_window_scaling
@ -78,7 +77,6 @@ class CTk(tkinter.Tk):
super().minsize(self.apply_window_scaling(self.current_width), self.apply_window_scaling(self.current_height))
super().maxsize(self.apply_window_scaling(self.current_width), self.apply_window_scaling(self.current_height))
super().geometry(f"{self.apply_window_scaling(self.current_width)}x"+f"{self.apply_window_scaling(self.current_height)}")
print("set_scaling:", self.apply_window_scaling(self.current_width), self.max_width, self.min_width)
# set new scaled min and max with 400ms delay (otherwise it won't work for some reason)
self.after(400, self.set_scaled_min_max)
@ -103,7 +101,6 @@ class CTk(tkinter.Tk):
def mainloop(self, *args, **kwargs):
if not self.window_exists:
print("deiconify")
self.deiconify()
self.window_exists = True
super().mainloop(*args, **kwargs)
@ -133,7 +130,6 @@ class CTk(tkinter.Tk):
super().maxsize(self.apply_window_scaling(self.max_width), self.apply_window_scaling(self.max_height))
def geometry(self, geometry_string):
print("geometry:", geometry_string)
super().geometry(self.apply_geometry_scaling(geometry_string))
# update width and height attributes

View File

@ -73,7 +73,6 @@ class CTkToplevel(tkinter.Toplevel):
super().maxsize(self.apply_window_scaling(self.current_width), self.apply_window_scaling(self.current_height))
super().geometry(
f"{self.apply_window_scaling(self.current_width)}x" + f"{self.apply_window_scaling(self.current_height)}")
print("set_scaling:", self.apply_window_scaling(self.current_width), self.max_width, self.min_width)
# set new scaled min and max with 400ms delay (otherwise it won't work for some reason)
self.after(400, self.set_scaled_min_max)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 395 KiB

After

Width:  |  Height:  |  Size: 395 KiB

View File

@ -14,9 +14,8 @@ class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.title("CustomTkinter complex example")
self.title("CustomTkinter complex_example.py")
self.geometry(f"{App.WIDTH}x{App.HEIGHT}")
# self.minsize(App.WIDTH, App.HEIGHT)
self.protocol("WM_DELETE_WINDOW", self.on_closing) # call .on_closing() when app gets closed

View File

@ -12,7 +12,7 @@ PATH = os.path.dirname(os.path.realpath(__file__))
class App(customtkinter.CTk):
APP_NAME = "CustomTkinter background gradient image"
APP_NAME = "CustomTkinter example_background_image.py"
WIDTH = 900
HEIGHT = 600
@ -40,13 +40,13 @@ class App(customtkinter.CTk):
self.frame.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
self.label_1 = customtkinter.CTkLabel(master=self.frame, width=200, height=60,
fg_color=("gray70", "gray35"), text="CustomTkinter\ninterface example")
fg_color=("gray70", "gray25"), text="CustomTkinter\ninterface example")
self.label_1.place(relx=0.5, rely=0.3, anchor=tkinter.CENTER)
self.entry_1 = customtkinter.CTkEntry(master=self.frame, corner_radius=20, width=200, placeholder_text="username")
self.entry_1 = customtkinter.CTkEntry(master=self.frame, corner_radius=6, width=200, placeholder_text="username")
self.entry_1.place(relx=0.5, rely=0.52, anchor=tkinter.CENTER)
self.entry_2 = customtkinter.CTkEntry(master=self.frame, corner_radius=20, width=200, show="*", placeholder_text="password")
self.entry_2 = customtkinter.CTkEntry(master=self.frame, corner_radius=6, width=200, show="*", placeholder_text="password")
self.entry_2.place(relx=0.5, rely=0.6, anchor=tkinter.CENTER)
self.button_2 = customtkinter.CTkButton(master=self.frame, text="Login",

View File

@ -1,5 +1,5 @@
import tkinter
import customtkinter # <- import the CustomTkinter module
import customtkinter
from PIL import Image, ImageTk # <- import PIL for the images
import os
@ -8,9 +8,9 @@ PATH = os.path.dirname(os.path.realpath(__file__))
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
root_tk.geometry("450x260")
root_tk.title("CustomTkinter button images")
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
app.geometry("450x260")
app.title("CustomTkinter example_button_images.py")
def button_function():
@ -29,10 +29,10 @@ add_user_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/add-user.png
chat_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/chat.png").resize((image_size, image_size), Image.ANTIALIAS))
home_image = ImageTk.PhotoImage(Image.open(PATH + "/test_images/home.png").resize((image_size, image_size), Image.ANTIALIAS))
root_tk.grid_rowconfigure(0, weight=1)
root_tk.grid_columnconfigure(0, weight=1, minsize=200)
app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure(0, weight=1, minsize=200)
frame_1 = customtkinter.CTkFrame(master=root_tk, width=250, height=240, corner_radius=15)
frame_1 = customtkinter.CTkFrame(master=app, width=250, height=240, corner_radius=15)
frame_1.grid(row=0, column=0, padx=20, pady=20, sticky="nsew")
frame_1.grid_columnconfigure(0, weight=1)
@ -56,9 +56,9 @@ button_4 = customtkinter.CTkButton(master=frame_1, image=home_image, text="", wi
corner_radius=10, fg_color="gray40", hover_color="gray25", command=button_function)
button_4.grid(row=3, column=1, columnspan=1, padx=20, pady=10, sticky="e")
button_5 = customtkinter.CTkButton(master=root_tk, image=add_user_image, text="Add User", width=130, height=70, border_width=3,
button_5 = customtkinter.CTkButton(master=app, image=add_user_image, text="Add User", width=130, height=70, border_width=3,
corner_radius=10, compound="bottom", border_color="#D35B58", fg_color=("gray84", "gray25"), hover_color="#C77C78",
command=button_function)
button_5.grid(row=0, column=1, padx=20, pady=20)
root_tk.mainloop()
app.mainloop()

View File

@ -1,12 +1,12 @@
import tkinter
import customtkinter # <- import the CustomTkinter module
import customtkinter
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
# customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
root_tk.geometry("400x480")
root_tk.title("CustomTkinter Test")
app = customtkinter.CTk() # create CTk window like you do with the Tk window
app.geometry("400x480")
app.title("CustomTkinter simple_example.py")
def button_function():
@ -23,7 +23,7 @@ def check_box_function():
y_padding = 13
frame_1 = customtkinter.CTkFrame(master=root_tk, corner_radius=15)
frame_1 = customtkinter.CTkFrame(master=app, corner_radius=15)
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
label_1 = customtkinter.CTkLabel(master=frame_1, justify=tkinter.LEFT)
@ -58,4 +58,4 @@ s_var = tkinter.StringVar(value="on")
switch_1 = customtkinter.CTkSwitch(master=frame_1)
switch_1.pack(pady=y_padding, padx=10)
root_tk.mainloop()
app.mainloop()

View File

@ -3,7 +3,7 @@ import tkinter
app = tkinter.Tk()
app.geometry("400x350")
app.title("Standard Tkinter Test")
app.title("simple_example_standard_tkinter.py")
def button_function():

View File

@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
github_url = "https://github.com/TomSchimansky/CustomTkinter"
[tool.tbump.version]
current = "4.0.0"
current = "4.0.4"
# Example of a semver regexp.
# Make sure this matches current_version before

View File

@ -1,7 +1,7 @@
[metadata]
name = customtkinter
version = 4.0.0
description = Create modern looking GUIs with tkinter and Python
version = 4.0.4
description = Create modern looking GUIs with Python
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/TomSchimansky/CustomTkinter
@ -14,10 +14,12 @@ classifiers =
Programming Language :: Python :: 3 :: Only
[options]
python_requires = >=3.7
packages =
customtkinter
customtkinter.widgets
customtkinter.windows
install_requires =
darkdetect
typing_extensions; python_version<="3.7"
include_package_data = True

View File

@ -1,9 +1,7 @@
from tkinter.constants import CENTER, LEFT
import tkinter
import tkinter.messagebox
from tkinter import filedialog as fd
import customtkinter # <- import the CustomTkinter module
import os
import customtkinter
class App(customtkinter.CTk):
@ -32,7 +30,6 @@ class App(customtkinter.CTk):
height=App.HEIGHT-40,
corner_radius=5)
self.frame_left.place(relx=0.38, rely=0.5, anchor=tkinter.E)
print(self.frame_left.widget_scaling)
self.frame_right = customtkinter.CTkFrame(master=self,
width=350,
@ -65,4 +62,4 @@ class App(customtkinter.CTk):
if __name__ == "__main__":
app = App()
app.start()
app.start()

View File

@ -1,5 +1,4 @@
import customtkinter
import tkinter
customtkinter.set_default_color_theme("blue")
customtkinter.set_appearance_mode("dark")

View File

@ -1,33 +0,0 @@
import tkinter
import customtkinter # <- import the CustomTkinter module
customtkinter.set_appearance_mode("System") # Other: "Dark", "Light"
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
root_tk.geometry("400x240")
root_tk.title("CustomTkinter Test")
def change_button_2_state():
if button_2.state == tkinter.NORMAL:
button_2.configure(state=tkinter.DISABLED)
elif button_2.state == tkinter.DISABLED:
button_2.configure(state=tkinter.NORMAL)
def button_2_click():
print("button_2 clicked")
frame_1 = customtkinter.CTkFrame(master=root_tk, width=300, height=200, corner_radius=15)
frame_1.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
button_1 = customtkinter.CTkButton(master=frame_1, text="Disable/Enable Button_2",
corner_radius=10, command=change_button_2_state, width=200)
button_1.place(relx=0.5, rely=0.3, anchor=tkinter.CENTER)
button_2 = customtkinter.CTkButton(master=frame_1, text="Button_2",
corner_radius=10, command=button_2_click)
button_2.place(relx=0.5, rely=0.7, anchor=tkinter.CENTER)
root_tk.mainloop()

View File

@ -1,4 +1,3 @@
import tkinter
import customtkinter
@ -15,11 +14,9 @@ class ExampleApp(customtkinter.CTk):
window = customtkinter.CTkToplevel(self)
window.geometry("400x200")
print(window.master.winfo_class())
label = customtkinter.CTkLabel(window, text="CTkToplevel window")
label.pack(side="top", fill="both", expand=True, padx=40, pady=40)
app = ExampleApp()
app.mainloop()
app.mainloop()

View File

@ -1,22 +1,21 @@
import tkinter
import customtkinter
root_tk = customtkinter.CTk()
root_tk.geometry("400x240")
app = customtkinter.CTk()
app.geometry("400x240")
def button_function():
top = customtkinter.CTkToplevel(root_tk)
top = customtkinter.CTkToplevel(app)
root_tk.after(1000, top.iconify) # hide toplevel
root_tk.after(1500, top.deiconify) # show toplevel
root_tk.after(2500, root_tk.iconify) # hide root_tk
root_tk.after(3000, root_tk.deiconify) # show root_tk
root_tk.after(4000, root_tk.destroy) # destroy everything
app.after(1000, top.iconify) # hide toplevel
app.after(1500, top.deiconify) # show toplevel
app.after(2500, app.iconify) # hide app
app.after(3000, app.deiconify) # show app
app.after(4000, app.destroy) # destroy everything
button = customtkinter.CTkButton(root_tk, command=button_function)
button = customtkinter.CTkButton(app, command=button_function)
button.pack(pady=20, padx=20)
root_tk.mainloop()
app.mainloop()

View File

@ -3,8 +3,8 @@ import tkinter
# customtkinter.set_appearance_mode("light")
root_tk = customtkinter.CTk()
root_tk.geometry("600x500")
app = customtkinter.CTk()
app.geometry("600x500")
menu = tkinter.Menu(tearoff=0, bd=0, relief=tkinter.FLAT, activeforeground="red")
menu.add_command(label="System")
@ -45,9 +45,9 @@ class CTkMenu(tkinter.Toplevel):
def open_menu():
menu = CTkMenu(root_tk, button.winfo_rootx(), button.winfo_rooty() + button.winfo_height() + 4, ["Option 1", "Option 2", "Point 3"])
menu = CTkMenu(app, button.winfo_rootx(), button.winfo_rooty() + button.winfo_height() + 4, ["Option 1", "Option 2", "Point 3"])
button = customtkinter.CTkButton(command=open_menu, height=50)
button.pack(pady=20)
root_tk.mainloop()
app.mainloop()

View File

@ -6,17 +6,17 @@ customtkinter.ScalingTracker.set_window_scaling(0.5)
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
root_tk.geometry("400x600")
root_tk.title("CustomTkinter manual scaling test")
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
app.geometry("400x600")
app.title("CustomTkinter manual scaling test")
#root_tk.minsize(200, 200)
#root_tk.maxsize(520, 520)
#root_tk.resizable(True, False)
#app.minsize(200, 200)
#app.maxsize(520, 520)
#app.resizable(True, False)
def button_function():
root_tk.geometry(f"{200}x{200}")
app.geometry(f"{200}x{200}")
print("Button click", label_1.text_label.cget("text"))
@ -29,7 +29,7 @@ def slider_function(value):
y_padding = 13
frame_1 = customtkinter.CTkFrame(master=root_tk, height=550, width=300)
frame_1 = customtkinter.CTkFrame(master=app, height=550, width=300)
frame_1.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
label_1 = customtkinter.CTkLabel(master=frame_1, justify=tkinter.LEFT)
label_1.place(relx=0.5, y=50, anchor=tkinter.CENTER)
@ -53,4 +53,4 @@ s_var = tkinter.StringVar(value="on")
switch_1 = customtkinter.CTkSwitch(master=frame_1)
switch_1.place(relx=0.5, y=450, anchor=tkinter.CENTER)
root_tk.mainloop()
app.mainloop()

View File

@ -6,32 +6,33 @@ customtkinter.ScalingTracker.set_window_scaling(0.5)
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
root_tk.geometry("400x480")
root_tk.title("CustomTkinter manual scaling test")
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
app.geometry("400x480")
app.title("CustomTkinter manual scaling test")
top_tk = customtkinter.CTkToplevel(root_tk)
top_tk = customtkinter.CTkToplevel(app)
top_tk.geometry("500x500")
#root_tk.minsize(200, 200)
#root_tk.maxsize(520, 520)
#root_tk.resizable(True, False)
#app.minsize(200, 200)
#app.maxsize(520, 520)
#app.resizable(True, False)
def button_function():
root_tk.geometry(f"{200}x{200}")
app.geometry(f"{200}x{200}")
print("Button click", label_1.text_label.cget("text"))
def slider_function(value):
customtkinter.set_widget_scaling(value * 2)
customtkinter.ScalingTracker.set_window_scaling(value * 2)
customtkinter.set_spacing_scaling(value * 2)
customtkinter.set_window_scaling(value * 2)
progressbar_1.set(value)
y_padding = 13
frame_1 = customtkinter.CTkFrame(master=root_tk)
frame_1 = customtkinter.CTkFrame(master=app)
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
label_1 = customtkinter.CTkLabel(master=frame_1, justify=tkinter.LEFT)
label_1.pack(pady=y_padding, padx=10)
@ -77,4 +78,4 @@ radiobutton_2.pack(pady=y_padding, padx=10)
switch_1 = customtkinter.CTkSwitch(master=top_tk)
switch_1.pack(pady=y_padding, padx=10)
root_tk.mainloop()
app.mainloop()

View File

@ -1,16 +0,0 @@
import tkinter
app = tkinter.Tk()
app.geometry("600x500")
canvas = tkinter.Canvas(master=app, highlightthickness=0, bg="gray30")
canvas.pack(expand=True, fill="both")
text_1 = canvas.create_text(100, 100, text="", font=('Helvetica', -4, 'bold'))
text_2 = canvas.create_text(100, 200, text="", font=('Helvetica', -8, 'bold'))
text_3 = canvas.create_text(100, 300, text="", font=('Helvetica', -12, 'bold'))
text_4 = canvas.create_text(100, 400, text="", font=('Helvetica', -20, 'bold'))
text_5 = canvas.create_text(400, 400, text="", font=('Helvetica', -100, 'bold'))
app.mainloop()

View File

@ -1,5 +1,4 @@
import customtkinter
import tkinter
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("blue")
@ -22,8 +21,8 @@ def button_click_event():
button = customtkinter.CTkButton(app, text="Open Dialog", command=button_click_event)
button.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
button.place(relx=0.5, rely=0.5, anchor=customtkinter.CENTER)
c1 = customtkinter.CTkCheckBox(app, text="dark mode", command=change_mode)
c1.place(relx=0.5, rely=0.8, anchor=tkinter.CENTER)
c1.place(relx=0.5, rely=0.8, anchor=customtkinter.CENTER)
app.mainloop()
app.mainloop()

View File

@ -1,63 +1,63 @@
import tkinter
import customtkinter # <- import the CustomTkinter module
import customtkinter
TEST_CONFIGURE = True
TEST_REMOVING = False
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
root_tk.geometry("400x600")
root_tk.title("Tkinter Variable Test")
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
app.geometry("400x600")
app.title("Tkinter Variable Test")
txt_var = tkinter.StringVar(value="")
entry_1 = customtkinter.CTkEntry(root_tk, width=200, textvariable=txt_var)
entry_1 = customtkinter.CTkEntry(app, width=200, textvariable=txt_var)
entry_1.pack(pady=15)
txt_var.set("new text wjkfjdshkjfb")
if TEST_CONFIGURE: entry_1.configure(textvariable=txt_var)
if TEST_REMOVING: entry_1.configure(textvariable="")
label_1 = customtkinter.CTkLabel(root_tk, width=200, textvariable=txt_var)
label_1 = customtkinter.CTkLabel(app, width=200, textvariable=txt_var)
label_1.pack(pady=15)
if TEST_CONFIGURE: label_1.configure(textvariable=txt_var)
if TEST_REMOVING: label_1.configure(textvariable="")
button_1 = customtkinter.CTkButton(root_tk, width=200, textvariable=txt_var)
button_1 = customtkinter.CTkButton(app, width=200, textvariable=txt_var)
button_1.pack(pady=15)
int_var = tkinter.IntVar(value=10)
if TEST_CONFIGURE: button_1.configure(textvariable=int_var)
if TEST_REMOVING: button_1.configure(textvariable="")
slider_1 = customtkinter.CTkSlider(root_tk, width=200, from_=0, to=3, variable=int_var)
slider_1 = customtkinter.CTkSlider(app, width=200, from_=0, to=3, variable=int_var)
slider_1.pack(pady=15)
if TEST_CONFIGURE: slider_1.configure(variable=int_var)
if TEST_REMOVING: slider_1.configure(variable="")
int_var.set(2)
slider_2 = customtkinter.CTkSlider(root_tk, width=200, from_=0, to=3, variable=int_var)
slider_2 = customtkinter.CTkSlider(app, width=200, from_=0, to=3, variable=int_var)
slider_2.pack(pady=15)
if TEST_CONFIGURE: slider_2.configure(variable=int_var)
if TEST_REMOVING: slider_2.configure(variable="")
label_2 = customtkinter.CTkLabel(root_tk, width=200, textvariable=int_var)
label_2 = customtkinter.CTkLabel(app, width=200, textvariable=int_var)
label_2.pack(pady=15)
progress_1 = customtkinter.CTkProgressBar(root_tk, width=200, variable=int_var)
progress_1 = customtkinter.CTkProgressBar(app, width=200, variable=int_var)
progress_1.pack(pady=15)
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(root_tk, 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")
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())
check_2 = customtkinter.CTkCheckBox(root_tk, text="check 2", variable=check_var, onvalue="on", offvalue="off")
check_2 = customtkinter.CTkCheckBox(app, text="check 2", variable=check_var, onvalue="on", offvalue="off")
check_2.pack(pady=15)
if TEST_CONFIGURE: check_2.configure(variable=check_var)
if TEST_REMOVING: check_2.configure(variable="")
label_3 = customtkinter.CTkLabel(root_tk, width=200, textvariable=check_var)
label_3 = customtkinter.CTkLabel(app, width=200, textvariable=check_var)
label_3.pack(pady=15)
label_3.configure(textvariable=check_var)
@ -65,10 +65,10 @@ def switch_event():
print("switch event")
s_var = tkinter.StringVar(value="on")
switch_1 = customtkinter.CTkSwitch(master=root_tk, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off", command=switch_event)
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=root_tk, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off")
switch_1 = customtkinter.CTkSwitch(master=app, variable=s_var, textvariable=s_var, onvalue="on", offvalue="off")
switch_1.pack(pady=20, padx=10)
#switch_1.toggle()
root_tk.mainloop()
app.mainloop()

View File

@ -4,28 +4,28 @@ import customtkinter
customtkinter.set_appearance_mode("light")
root_tk = customtkinter.CTk()
root_tk.geometry("1400x480")
root_tk.title("CustomTkinter TTk Compatibility Test")
app = customtkinter.CTk()
app.geometry("1400x480")
app.title("CustomTkinter TTk Compatibility Test")
root_tk.grid_rowconfigure(0, weight=1)
root_tk.grid_columnconfigure((0, 1, 2, 3, 5, 6), weight=1)
app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure((0, 1, 2, 3, 5, 6), weight=1)
button_0 = customtkinter.CTkButton(root_tk)
button_0 = customtkinter.CTkButton(app)
button_0.grid(padx=20, pady=20, row=0, column=0)
frame_1 = tkinter.Frame(master=root_tk)
frame_1 = tkinter.Frame(master=app)
frame_1.grid(padx=20, pady=20, row=0, column=1, sticky="nsew")
button_1 = customtkinter.CTkButton(frame_1, text="tkinter.Frame")
button_1.pack(pady=20, padx=20)
frame_2 = tkinter.LabelFrame(master=root_tk, text="Tkinter LabelFrame")
frame_2 = tkinter.LabelFrame(master=app, text="Tkinter LabelFrame")
frame_2.grid(padx=20, pady=20, row=0, column=2, sticky="nsew")
button_2 = customtkinter.CTkButton(frame_2, text="tkinter.LabelFrame")
button_2.pack(pady=20, padx=20)
frame_3 = customtkinter.CTkFrame(master=root_tk)
frame_3 = customtkinter.CTkFrame(master=app)
frame_3.grid(padx=20, pady=20, row=0, column=3, sticky="nsew")
label_3 = customtkinter.CTkLabel(master=frame_3, text="CTkFrame Label", fg_color=("gray95", "gray15"))
label_3.grid(row=0, column=0, columnspan=1, padx=5, pady=5, sticky="ew")
@ -34,17 +34,17 @@ button_3.grid(row=1, column=0, padx=20)
frame_3.grid_rowconfigure(1, weight=1)
frame_3.grid_columnconfigure((0, ), weight=1)
frame_4 = ttk.Frame(master=root_tk)
frame_4 = ttk.Frame(master=app)
frame_4.grid(padx=20, pady=20, row=0, column=4, sticky="nsew")
button_4 = customtkinter.CTkButton(frame_4, text="ttk.Frame")
button_4.pack(pady=20, padx=20)
frame_5 = ttk.LabelFrame(master=root_tk, text="TTk LabelFrame")
frame_5 = ttk.LabelFrame(master=app, text="TTk LabelFrame")
frame_5.grid(padx=20, pady=20, row=0, column=5, sticky="nsew")
button_5 = customtkinter.CTkButton(frame_5)
button_5.pack(pady=20, padx=20)
frame_6 = ttk.Notebook(master=root_tk)
frame_6 = ttk.Notebook(master=app)
frame_6.grid(padx=20, pady=20, row=0, column=6, sticky="nsew")
button_6 = customtkinter.CTkButton(frame_6, text="ttk.Notebook")
button_6.pack(pady=20, padx=20)
@ -52,4 +52,4 @@ button_6.pack(pady=20, padx=20)
ttk_style = ttk.Style()
ttk_style.configure(frame_3.winfo_class(), background='red')
root_tk.mainloop()
app.mainloop()

View File

@ -1,25 +1,25 @@
import customtkinter
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
root_tk.geometry("400x650")
root_tk.title("test_vertical_widgets")
app = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
app.geometry("400x650")
app.title("test_vertical_widgets")
root_tk.grid_columnconfigure(0, weight=1)
root_tk.grid_rowconfigure((0, 1, 2, 3), weight=1)
app.grid_columnconfigure(0, weight=1)
app.grid_rowconfigure((0, 1, 2, 3), weight=1)
progressbar_1 = customtkinter.CTkProgressBar(root_tk, orient="horizontal")
progressbar_1 = customtkinter.CTkProgressBar(app, orient="horizontal")
progressbar_1.grid(row=0, column=0, pady=20, padx=20)
progressbar_2 = customtkinter.CTkProgressBar(root_tk, orient="vertical")
progressbar_2 = customtkinter.CTkProgressBar(app, orient="vertical")
progressbar_2.grid(row=1, column=0, pady=20, padx=20)
slider_1 = customtkinter.CTkSlider(root_tk, orient="horizontal", command=progressbar_1.set,
slider_1 = customtkinter.CTkSlider(app, orient="horizontal", command=progressbar_1.set,
button_corner_radius=3, button_length=20)
slider_1.grid(row=2, column=0, pady=20, padx=20)
slider_2 = customtkinter.CTkSlider(root_tk, orient="vertical", command=progressbar_2.set,
slider_2 = customtkinter.CTkSlider(app, orient="vertical", command=progressbar_2.set,
button_corner_radius=3, button_length=20)
slider_2.grid(row=3, column=0, pady=20, padx=20)
root_tk.mainloop()
app.mainloop()

View File

@ -0,0 +1,47 @@
import tkinter
import customtkinter
app = customtkinter.CTk()
app.geometry("400x800")
app.title("CustomTkinter Test")
def change_state(widget):
if widget.state == tkinter.NORMAL:
widget.configure(state=tkinter.DISABLED)
elif widget.state == tkinter.DISABLED:
widget.configure(state=tkinter.NORMAL)
def widget_click():
print("widget clicked")
button_1 = customtkinter.CTkButton(master=app, text="button_1", command=widget_click)
button_1.pack(padx=20, pady=(20, 10))
button_2 = customtkinter.CTkButton(master=app, text="Disable/Enable button_1", command=lambda: change_state(button_1))
button_2.pack(padx=20, pady=(10, 20))
switch_1 = customtkinter.CTkSwitch(master=app, text="switch_1", command=widget_click)
switch_1.pack(padx=20, pady=(20, 10))
button_2 = customtkinter.CTkButton(master=app, text="Disable/Enable switch_1", command=lambda: change_state(switch_1))
button_2.pack(padx=20, pady=(10, 20))
entry_1 = customtkinter.CTkEntry(master=app, placeholder_text="entry_1")
entry_1.pack(padx=20, pady=(20, 10))
button_3 = customtkinter.CTkButton(master=app, text="Disable/Enable entry_1", command=lambda: change_state(entry_1))
button_3.pack(padx=20, pady=(10, 20))
checkbox_1 = customtkinter.CTkCheckBox(master=app, text="checkbox_1")
checkbox_1.pack(padx=20, pady=(20, 10))
button_4 = customtkinter.CTkButton(master=app, text="Disable/Enable checkbox_1", command=lambda: change_state(checkbox_1))
button_4.pack(padx=20, pady=(10, 20))
radiobutton_1 = customtkinter.CTkRadioButton(master=app, text="radiobutton_1")
radiobutton_1.pack(padx=20, pady=(20, 10))
button_5 = customtkinter.CTkButton(master=app, text="Disable/Enable entry_1", command=lambda: change_state(radiobutton_1))
button_5.pack(padx=20, pady=(10, 20))
app.mainloop()

View File

@ -62,20 +62,15 @@ class TestCTk():
customtkinter.ScalingTracker.set_window_scaling(1.5)
self.root_ctk.geometry("300x400")
self.root_ctk.update()
assert self.root_ctk.current_width == 300 and self.root_ctk.current_height == 400
assert round(self.root_ctk.winfo_width()) == 450 and round(self.root_ctk.winfo_height()) == 600
assert self.root_ctk.window_scaling == 1.5 * customtkinter.ScalingTracker.get_window_dpi_scaling(self.root_ctk)
self.root_ctk.maxsize(400, 500)
self.root_ctk.geometry("500x500")
self.root_ctk.update()
assert self.root_ctk.current_width == 400 and self.root_ctk.current_height == 500
assert round(self.root_ctk.winfo_width()) == 600 and round(self.root_ctk.winfo_height()) == 750
customtkinter.ScalingTracker.set_window_scaling(1)
self.root_ctk.update()
assert self.root_ctk.current_width == 400 and self.root_ctk.current_height == 500
assert round(self.root_ctk.winfo_width()) == 400 and round(self.root_ctk.winfo_height()) == 500
print("successful")
def test_configure(self):

View File

@ -64,20 +64,15 @@ class TestCTkToplevel():
customtkinter.ScalingTracker.set_window_scaling(1.5)
self.ctk_toplevel.geometry("300x400")
self.ctk_toplevel.update()
assert self.ctk_toplevel.current_width == 300 and self.ctk_toplevel.current_height == 400
assert round(self.ctk_toplevel.winfo_width()) == 450 and round(self.ctk_toplevel.winfo_height()) == 600
assert self.root_ctk.window_scaling == 1.5 * customtkinter.ScalingTracker.get_window_dpi_scaling(self.root_ctk)
self.ctk_toplevel.maxsize(400, 500)
self.ctk_toplevel.geometry("500x500")
self.ctk_toplevel.update()
assert self.ctk_toplevel.current_width == 400 and self.ctk_toplevel.current_height == 500
assert round(self.ctk_toplevel.winfo_width()) == 600 and round(self.ctk_toplevel.winfo_height()) == 750
customtkinter.ScalingTracker.set_window_scaling(1)
self.ctk_toplevel.update()
assert self.ctk_toplevel.current_width == 400 and self.ctk_toplevel.current_height == 500
assert round(self.ctk_toplevel.winfo_width()) == 400 and round(self.ctk_toplevel.winfo_height()) == 500
print("successful")
def test_configure(self):