About customtkinter
CustomTkinter is a tkinter-based library for building Python graphical interfaces. Its guidance covers themed windows, appearance settings, and common layout methods.
Key features
- 01Create main and secondary windows
- 02Set light or dark appearance
- 03Configure a default color theme
- 04Arrange widgets with pack, grid, or place
Use cases
- 01Build a Python graphical application
- 02Set an app’s light or dark appearance
- 03Create forms, tabs, or scrollable areas
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ kenvindev/ customtkinter-skill --skill customtkinterAfter installing, type/customtkinterin Claude Code to confirm it loaded.
Bundled filesexamples.mdreference.md
Details
From the project READMECustomTkinter
Quick Start
import customtkinter
app = customtkinter.CTk()
app.geometry("600x500")
app.title("My App")
# thêm widgets...
app.mainloop()
Cài đặt: pip install customtkinter
Quy tắc chung
- Dùng CTk() thay vì Tk() – Theme chỉ áp dụng khi dùng CTk. Không dùng
tkinter.Tk(). - Một instance CTk duy nhất – Chỉ một cửa sổ chính, gọi
.mainloop()một lần. - Cửa sổ phụ – Dùng
CTkToplevel(master). Không gọi mainloop cho toplevel. - Layout – Dùng
pack(),grid(), hoặcplace()như tkinter chuẩn.
Cấu trúc app với class
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.geometry("600x500")
self.title("My App")
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
# thêm widgets...
app = App()
app.mainloop()
Màu sắc
- Single color:
fg_color="red"hoặcfg_color="#FF0000" - Tuple (light, dark):
fg_color=("#DB3E39", "#821D1A")– tự chọn theo appearance mode
Theme và Appearance
# Trước khi tạo CTk()
customtkinter.set_appearance_mode("system") # "dark" | "light" | "system"
customtkinter.set_default_color_theme("blue") # "blue" | "green" | "dark-blue" | "path/to.json"
Toplevel – tránh mở trùng cửa sổ
def open_toplevel(self):
if self.toplevel_window is None or not self.toplevel_window.winfo_exists():
self.toplevel_window = ToplevelWindow(self)
else:
self.toplevel_window.focus()
Tài liệu bổ sung
- Chi tiết API widgets, windows, colors, packaging: reference.md
- Mẫu code: app cơ bản, form, tabview, scrollable frame, dialog: examples.md
Comments
Markdown supported