Skip to main content
rule

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.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/customtkinter.mdc
Open on GitHub

What 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 customtkinter interface 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 customtkinter app so the CTk subclass owns the interface logic.
  • Separate widget construction from button click handling in this Python project.
  • Review my Python files against the customtkinter application structure guidelines.

How to install customtkinter

Manually: put the files in place

.cursor/rules/customtkinter.mdc

Frontmatter: description, globs, alwaysApply

Step 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

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set240

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor