Skip to content

CTkTextbox

Tom Schimansky edited this page Oct 14, 2022 · 6 revisions

Widget will be available with version 5.0.0!

Bildschirmfoto 2022-10-14 um 19 15 30

Example Code:

textbox = customtkinter.CTkTextbox(app)
textbox.grid(row=0, column=0)

textbox.insert("0.0", "new text to insert")  # insert at line 0 character 0
text = textbox.get("0.0", "end")  # get text from line 0 character 0 till the end

textbox.configure(state="disabled")  # configure textbox to be read-only

Arguments:

argument value
master root, frame, top-level
width box width in px
height box height in px
corner_radius corner radius in px
border_width border width in px
border_spacing minimum space between text and widget border, default is 3. Set to 0 for the text to touch the widget border (if corner_radius=0)
fg_color main widget color, tuple: (light_color, dark_color) or single color
border_color border color, tuple: (light_color, dark_color) or single color
text_color text color, tuple: (light_color, dark_color) or single color
scrollbar_color main color of scrollbar, tuple: (light_color, dark_color) or single color
scrollbar_hover_color hover color of scrollbar, tuple: (light_color, dark_color) or single color
font text font, tuple: (font_name, size)
activate_scrollbars default is True, set to False to prevent scrollbars from appearing
state "normal" (standard) or "disabled" (not clickable, read-only)

and the following arguments of the tkinter.Text class:

"autoseparators", "cursor", "exportselection", "insertborderwidth", "insertofftime", "insertontime", "insertwidth", "maxundo", "padx", "pady", "selectborderwidth", "spacing1", "spacing2", "spacing3", "state", "tabs", "takefocus", "undo", "wrap", "xscrollcommand", "yscrollcommand"

Methods:

  • .configure(attribute=value, ...)

    All attributes can be configured and updated.

    textbox.configure(state=..., text_color=..., ...)
  • .cget(attribute_name)

    Get values of all attributes specified as string.

  • .bind(sequence=None, command=None, add=None)

    Bind commands to events specified by sequence string.

  • .unbind(sequence, funcid=None)

    Unbind command from sequence specified by funcid, which is returned by .bind().

  • .insert(index, text, tags=None)

    Insert text at given index. Index for the tkinter.Text class is specified by 'line.character', 'end', 'insert' or other keywords described here: https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/text-index.html

  • .delete(self, index1, index2=None)

    Delete the characters between index1 and index2 (not included).

  • .get(index1, index2=None)

    Return the text from INDEX1 to INDEX2 (not included).

  • .focus_set()

    Set focus to the text widget.

and nearly all other methods of tkinter.Text described here: https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/text-methods.html

⚠️ Attention ⚠️

The Github Wiki is outdated, the new documentation can be found at:

https://customtkinter.tomschimansky.com

Clone this wiki locally