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.1.tar.gz (21.2 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.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ctkcodeboxplus-1.1.tar.gz
Algorithm Hash digest
SHA256 225a707ffae9a8dcbcb222e7f18e007b5aa02ff69288d538c0c125403b259722
MD5 eb0fb26cb03df8b5e4037c4ef3c0f9ce
BLAKE2b-256 325a829bc7326b84a80c1375adaaca9b7896160324de6b62d80dd8e8d456e236

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctkcodeboxplus-1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: ctkcodeboxplus-1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 982619c5e1996ef74415d67254882fc54ee01b0141530ce8f5b7915aed6eb2e9
MD5 b8621d2cb52db3a7b7b373a89fc898b8
BLAKE2b-256 b1af5000a45d337766a0005425cdfa71d5d1f08be6fe88f54298e55f03a6cf9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ctkcodeboxplus-1.1-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