Thonny is a beginner-friendly Python IDE, but “wrap text” can mean two different things. One meaning is editor word wrap: long code lines visually continue on the next screen line. The other meaning is Python text wrapping: your program formats long strings for output. These are not the same, and mixing them up can break Python syntax.
The official Thonny website presents Thonny as a beginner-focused Python IDE with a simple interface, debugger, and variable view. Public Thonny discussions also show that editor word wrap has been requested over time, including the open word wrap issue on the Thonny repository. For program output, Python’s official textwrap documentation is the right reference.
Quick answer
If you want readable code in Thonny, manually break long Python statements using parentheses, commas, and normal Python syntax. If you want your program to wrap long displayed text, use the textwrap module. Do not rely on visual wrapping to change how Python reads your code.
1. Break long function calls safely
Python lets you split long expressions across multiple lines inside parentheses. This is the safest way to keep Thonny editor lines readable without changing program behavior.
result = max(
14,
27,
9,
42,
)
print(result)
This is better than making one very long line. It also keeps indentation clear for beginners who are learning how Python blocks work.
2. Split long strings without changing output
When a string literal is too long, place adjacent string literals inside parentheses. Python joins them at runtime, while the source code stays readable in the editor.
message = (
"Thonny is useful for beginners because "
"it keeps the editor, shell, and debugger simple."
)
print(message)
This technique is useful for messages, labels, and prompts. It avoids horizontal scrolling and does not insert unwanted line breaks into the actual string.
3. Wrap comments manually
Comments are not automatically reinterpreted by Python. If a comment is long, make it several comment lines. This keeps explanations readable in Thonny and on smaller screens.
# Explain the reason for the calculation.
# Keep each comment line short enough
# that students can read it without scrolling.
total = 18 + 24
print(total)
Manual comment wrapping is especially helpful when teaching or presenting code because students can see the full explanation without resizing the IDE.
4. Wrap printed text with textwrap.wrap()
Use textwrap.wrap() when your program should split a paragraph into a list of shorter lines. This changes program output, not editor display.
import textwrap
text = "Python output can be wrapped so it fits into a narrow console window."
lines = textwrap.wrap(text, width=32)
for line in lines:
print(line)
The function returns a list of strings. You decide whether to print them, join them, or display them in a GUI.
5. Use textwrap.fill() for a wrapped paragraph
textwrap.fill() is a shortcut when you want one string with newline characters already inserted. It is convenient for console output and generated reports.
import textwrap
text = "Thonny keeps Python approachable, but long output still needs formatting."
wrapped = textwrap.fill(text, width=36)
print(wrapped)
If your goal is to wrap the output shown in the Thonny shell, fill() is usually easier than managing a list of lines yourself.
6. Shorten long previews
Sometimes wrapping is not enough. For table cells, status messages, or short previews, use textwrap.shorten() to collapse whitespace and add a placeholder.
import textwrap
summary = "This lesson explains how to keep long Python text readable in Thonny."
preview = textwrap.shorten(summary, width=48, placeholder="...")
print(preview)
This is useful when you want a concise message in a small area, not a multi-line paragraph.
Why this distinction matters
Soft wrapping is only a display feature. It changes how text appears on screen, but it does not add real newline characters. Manual Python line breaks are part of the source code and must follow syntax rules. Output wrapping with textwrap changes the string your program prints. Knowing which layer you are changing prevents confusing bugs.
What not to do
- Do not split a Python statement at a random place just because the editor line is long.
- Do not remove indentation to make code fit the screen.
- Do not confuse visual editor wrapping with newline characters inside a string.
- Do not assume every Thonny version has the same editor preferences.
- Do not use screenshots or body images when a clear code example is easier to maintain.
Practical workflow in Thonny
For code, keep lines short by using parentheses, helper variables, and readable comments. For output, use textwrap. For shell readability, clear old output when needed; our Python shell clearing guide covers that workflow. If your long text appears in a plot, our Matplotlib text guide is a better next step. For string cleanup, see our remove quotes from string guide.