customtkinter — Cursor rule for Python UI structure and theming
This Cursor rule guides agents toward class-based customtkinter applications and consistent UI setup. Use it when editing Python interfaces built with the library.
.cursor/rules/customtkinter.mdcWhat customtkinter does
The rule sets coding guidance for Python applications built with customtkinter. It recommends making the main application a class derived from customtkinter.CTk, keeping interface behavior together and making state easier to manage. Event handlers should not be tangled with widget creation.
Theme configuration and component organization are also part of the guidance. The included example shows a procedural window with a label, a button, and a click handler that prints a message. The rule uses this example to contrast a flat script with a class-based application structure.
Cursor targets Python files matching **/*.py. This is a set of instructions for the coding agent, not an installer for the customtkinter library. Projects using another GUI framework may not benefit from guidance written specifically for this one.
What it helps with
- Structure a
customtkinterinterface around an application class - Separate widget creation from button event handling
- Keep theme setup consistent across the application
- Make UI state easier to manage
Example prompts for the agent
- Refactor my
customtkinterapp so theCTksubclass owns the interface logic. - Separate widget construction from button click handling in this Python project.
- Review my Python files against the
customtkinterapplication structure guidelines.
How to install customtkinter
Manually: put the files in place
.cursor/rules/customtkinter.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/customtkinter.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/customtkinter.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/customtkinter.mdManually: put the files in place
.clinerules/customtkinter.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about customtkinter
How do I install the customtkinter rule in Cursor?
Add the rule file at .cursor/rules/customtkinter.mdc in your project. Cursor applies it to Python files matching **/*.py.
What does the customtkinter rule do?
It guides the coding agent when creating or modifying customtkinter interfaces. Its main focus is class-based application structure, UI state management, and theme configuration.
Which files does the rule apply to?
It targets files matching **/*.py. The recommendations are intended for customtkinter applications rather than every Python project.
Source text
customtkinter.mdc · CC0-1.0
---
description: Definitive guidelines for writing clean, maintainable, and performant customtkinter applications. This rule file enforces best practices for code structure, theming, component architecture, and common pitfalls.
globs: **/*.py
---
# customtkinter Best Practices
This document outlines the definitive best practices for developing applications with `customtkinter`. Adhering to these guidelines ensures your UI code is consistent, maintainable, performant, and leverages the full power of the library.
## 1. Code Organization: Class-Based Applications
Always structure your `customtkinter` applications using a class that inherits from `customtkinter.CTk`. This encapsulates UI logic, promotes modularity, and simplifies state management.
❌ BAD: Procedural spaghetti code
```python
import customtkinter as ctk
# Theme setup (often forgotten or inconsistent)
ctk.set_appearance_mode("System")
ctk.set_default_color_theme("blue")
app = ctk.CTk()
app.geometry("400x240")
app.title("My App")
def on_button_click():
print("Button clicked!")
# Logic mixed directly here
label = ctk.CTkLabel(app, text="Hello!")
label.pack(pady=10)
button = ctk.CTkButton(app, text="Click Me", command=on_button_click)
button.pack(pady=10)
app.mainloop()
```
✅
© sanjeed5 · CC0-1.0 · sanjeed5/awesome-cursor-rules-mdc