CustomTkinter
CustomTkinter is a Python UI library based on Tkinter, designed to create modern-looking and fully customizable graphical user interfaces. It provides a consistent and aesthetically pleasing experience across Windows, macOS, and Linux platforms, enhancing standard Tkinter widgets with advanced styling. The library is actively developed, with its current version being 5.2.2.
Warnings
- breaking Version 5.0.0 introduced significant breaking changes, including: `text_font` attributes renamed to `font`, transparent color values changing from `None` to the string `'transparent'`, and a complete overhaul of custom theme file formats.
- gotcha ModuleNotFoundError for 'customtkinter' often occurs due to incorrect Python interpreter selection in IDEs (like VS Code) when using virtual environments, or due to incorrect capitalization in import statements (e.g., `from CustomTkinter import CTk`).
- gotcha Displaying images within CustomTkinter widgets (e.g., `CTkButton` or `CTkLabel`) requires the Pillow library to be installed separately, as it is an optional dependency.
- gotcha CustomTkinter, being built on Tkinter, implicitly relies on the Tcl/Tk GUI toolkit. While typically bundled with Python, some environments (especially minimal Linux installations or specific Python builds) may require manual installation of Tcl/Tk system packages.
Install
-
pip install customtkinter
Imports
- customtkinter
import customtkinter
- CTk
import customtkinter as ctk app = ctk.CTk()
Quickstart
import customtkinter
customtkinter.set_appearance_mode("System") # Modes: "System" (default), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (default), "dark-blue", "green"
app = customtkinter.CTk() # create CTk window
app.geometry("400x240")
app.title("My CTk App")
def button_function():
print("Button pressed!")
# Create a button
button = customtkinter.CTkButton(master=app, text="Click Me", command=button_function)
button.place(relx=0.5, rely=0.5, anchor=customtkinter.CENTER)
app.mainloop()