Skip to main content

A code editor widget for customtkinter with enhanced features

Project description

CTkCodeBoxPlus

A code editor widget for customtkinter (Enhanced Edition). image

Features

  • Multiple language support
  • Code syntax highlighting
  • Line highlighting (Enhanced)
  • Auto-Indent and Outdent (Enhanced)
  • Custom history with undo and redo (Enhanced)
  • Smart selection on double and triple click (Enhanced)
  • Implemented actions like copy, paste, cut (Enhanced)
  • Keybindings for implemented actions (Enhanced)
  • Multiple Themes
  • Right-click menu (Enhanced)
  • Line numbers on left side
  • Fully customizable
  • Easy to Use

Installation

pip install CTkCodeBoxPlus

Simple Usage

import customtkinter
from CTkCodeBoxPlus import *

root = customtkinter.CTk()

codebox = CTkCodeBox(root, language="python")
codebox.pack(padx=10, pady=10, expand=True,fill="both")

root.mainloop()

Arguments

Parameter Type Default Description
master Widget - Parent widget
language str/pygments.lexer.Lexer - Pygments language name (str) or a lexer class
height int 200 Widget height in pixels (passed to CTkTextbox)
theme str "solarized-light" Pygments style name used for highlighting
numbering_settings NumberingSettings NumberingSettings() NumberingSettings object for the line nums
menu_settings MenuSettings MenuSettings() MenuSettings object for the context menu
wrap bool True Enable word wrap
select_color str None Override selection background color
cursor_color str None Cursor color I (blinking)
highlight_current_line bool True Highlight the active line
highlight_current_line_color str None Explicit color for active line
history_settings HistorySettings HistorySettings() HistorySettings object for custom history.
indent_width int 4 Number of spaces for indent/outdent.
**kwargs various - Additional CTkTextBox parameters

Methods

  • .insert(index, code, push_history): Insert code/text in the box and trigger a non-editing highlight update with pushing history (if push_history is True)
  • .get(index1, index2): Get code/text from the box
  • .configure(kwargs): Change parameters of the codebox
  • .cget(parameter): Get the parameter value from the codebox by name
  • .update_code(): Schedule a debounced re-highlight and update edited flag
  • .clear_code(): Remove all highlighting tags while preserving selection
  • .set_wrap(enabled): Enable/disable word wrap
  • .toggle_wrap(): Toggle wrap mode
  • .is_edited(): Return True if the text has been edited since last reset
  • .reset_edited(): Reset edited state flag to False
  • .cut_text(): Cut selected text to clipboard and notify change
  • .copy_text(): Copy selected text to clipboard
  • .paste_text(): Paste clipboard text, replacing selection if present, and refresh highlighting/lines with notify change
  • .clear_all_text(): Delete all content and notify change
  • .select_all_text(): Select all content
  • .set_history_enabled(enabled): Enable/disable the internal undo/redo history
  • .set_history_limit(limit): Set maximum number of undo frames to keep
  • .clear_history(): Clear undo and redo stacks
  • .undo(): Undo the last change if history is enabled
  • .redo(): Redo the last undone change if available

Dataclasses

@dataclass(frozen=True)
class MenuSettings:
    enabled: bool = True
    fg_color: Optional[str] = None
    text_color: Optional[str] = None
    hover_color: Optional[str] = None

@dataclass()
class HistorySettings:
    enabled: bool = True
    cooldown: int = 1500  #ms
    max: int = 100

@dataclass(frozen=True)
class NumberingSettings:
    enabled: bool = True
    color: Optional[str] = None
    justify: str = "left"
    padx: int = 30
    auto_padx: bool = True

Languages

More lexers available here: https://pygments.org/docs/lexers/

Color Themes

abap, arduino, autumn, borland, colorful, default, dracula, emacs, 
friendly_grayscale, friendly, fruity, github-dark, gruvbox-dark, 
gruvbox-light, igor, inkpot, lightbulb, lilypond, lovelace, manni, material, 
monokai, murphy, native, nord-darker, nord, one-dark, paraiso-dark, paraiso-light, 
pastie, perldoc, rainbow_dash, rrt, sas, solarized-dark, solarized-light, staroffice, 
stata-dark, stata-light, tango, trac, vim, vs, xcode, zenburn

More style examples given here: https://pygments.org/styles/


Support & Issues


Authors


License

This project is licensed under the MIT License.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ctkcodeboxplus-1.2.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctkcodeboxplus-1.2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file ctkcodeboxplus-1.2.tar.gz.

File metadata

  • Download URL: ctkcodeboxplus-1.2.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ctkcodeboxplus-1.2.tar.gz
Algorithm Hash digest
SHA256 e43e4602c0eda1a7588e15de69a23e268fb21c78477ba8344dc7bd2bec164cdd
MD5 05b1212949a0d6d6381f4b038cd22894
BLAKE2b-256 474d5e4d81481208c84eff26d370726b9180627ef0f60c2c3a5d1b9f48494f90

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctkcodeboxplus-1.2.tar.gz:

Publisher: publish-to-pypi.yml on KiTant/CTkCodeBoxPlus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ctkcodeboxplus-1.2-py3-none-any.whl.

File metadata

  • Download URL: ctkcodeboxplus-1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ctkcodeboxplus-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c3e7aca06e491983c77306026e384605c815b860ec8f271172d26b96e40f3bc
MD5 4c234b7ed4191ed1718bf12cf0b24ed0
BLAKE2b-256 dd17ad374f76cd8f80bde45a4c84e8dd8fded5c1f88b7e6645e1ef4b3115a0db

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctkcodeboxplus-1.2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on KiTant/CTkCodeBoxPlus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page