mcpField
C
customtkinter

customtkinter

github.com/kenvindev开发044 次安装34 周前更新
代码仓库

关于 customtkinter

CustomTkinter 是用于构建 Python 图形界面的 tkinter 扩展库,面向开发桌面应用的开发者。它提供主题、外观模式、窗口和布局组件的使用指导。

主要功能

  1. 01创建主窗口与辅助窗口
  2. 02设置浅色或深色外观
  3. 03配置默认颜色主题
  4. 04使用 pack、grid 或 place 布局

适用场景

  1. 01构建 Python 图形界面应用
  2. 02为应用设置明暗外观
  3. 03创建表单、标签页或滚动区域

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/kenvindev/customtkinter-skill --skill customtkinter

安装后在 Claude Code 中输入/customtkinter确认已加载。

附带文件examples.mdreference.md

详细介绍

CustomTkinter

快速入门

import customtkinter

app = customtkinter.CTk()
app.geometry("600x500")
app.title("My App")
# thêm widgets...
app.mainloop()

安装:pip install customtkinter

通用规则

  1. 使用 CTk() 而不是 Tk() – 只有使用 CTk 时主题才会生效。不要使用 tkinter.Tk()。
  2. 只创建一个 CTk 实例 – 仅创建一个主窗口,并调用一次 .mainloop()。
  3. 子窗口 – 使用 CTkToplevel(master)。不要为 toplevel 调用 mainloop。
  4. 布局 – 像使用标准 tkinter 一样,使用 pack()、grid() 或 place()。

使用类构建应用

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()

颜色

  • 单色:fg_color="red" 或 fg_color="#FF0000"
  • 元组(浅色、深色):fg_color=("#DB3E39", "#821D1A") – 根据外观模式自动选择

主题和外观

# 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 – 避免重复打开窗口

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()

补充文档

  • Widgets、窗口、颜色和打包的 API 详情:reference.md
  • 代码示例:基础应用、表单、tabview、可滚动框架、对话框:examples.md

评论

支持 Markdown