A code editor widget for customtkinter.
- Multiple language support
- Code syntax highlighting
- Multiple Themes
- Right-click copy-paste menu
- Line numbers on left side
- Fully customizable
- Easy to Use
Download the source code, paste the CTkCodeBox
folder in the directory where your program is present.
Requirements: Pygments and TkLineNums
import customtkinter
from CTkCodeBox import *
root = customtkinter.CTk()
codebox = CTkCodeBox(root, language="python")
codebox.pack(padx=10, pady=10, expand=True,fill="both")
root.mainloop()
Parameter | Description |
---|---|
width | change the default width of the widget |
height | change the default height of the widget |
fg_color | change the fg_color of the widget |
language | set the language lexer for the codebox |
theme | change the overall color theme for the code syntax |
line_numbering | boolean, enable or disable the line numbering |
numbering_color | change text color of the line numbering |
menu | boolean, enable or disable the right click popup menu |
menu_fg_color | color of the menu (optional) |
menu_text_color | text color of the menu buttons (optional) |
menu_hover_color | hover color of the menu buttons (optional) |
wrap | enable or disabled word wrapping in the textbox |
select_color | change the selection color of the codebox |
cursor_color | change the cursor color I (blinking) |
undo | boolean, enable or disable the undo text feature |
*Other Parameters | All other parameters of ctktextbox can be passed in ctkcodebox |
- .insert(index, code): insert code in the box
- .configure(kwargs): change parameters of the codebox
- .cget(parameter): get the parameter name from the codebox
- .update_code(): update the code syntax colors
- .clear_code(): delete all the code from the box
More lexers available here: https://pygments.org/docs/lexers/
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/
Follow me for more stuff like this: Akascape