Multiline text in Blender interface panels

Unfortunately, Blender’s interface does not support word wrapping and multi-line text blocks. Text lines that are too long to be displayed in the panel are cut off. However, multiline text can still be displayed on the panel using several text elements instead of one.

First, let’s create a simple panel in the N-panel of the 3D Viewport window and place a label element with the desired text on it.

Define the panel class and register it.

After executing this code by pressing the “Run Script” button, we will create a new panel “MULTILINE TEXT” on which the text “Loren Ipsum …” will be placed in a single line.

To make the text multi-line, let’s split it into separate lines by spaces according to the panel width.

The width of the current panel in pixels can be obtained from the area context.

Let’s make a function that will split a text line passed into it so that the length of each line does not exceed the panel width. We can use the “textwrap” module for this.

We pass three parameters to the function:

  • context – the window context to get the panel width
  • text – text to be shown
  • parent – the element on the interface panel on which we will display the text

The “textwrap” module splits text by characters, not by pixels. So we need to count how many characters will fit into a line of the desired length (panel width). Let’s use an average character width of 7 pixels.

Next, we will get a list of lines into which the text was split.

Next, we create the required number of label elements, each of which contains the next line of text.

Having the function let’s replace the text output in our panel with a call to this function. Now all the text is placed on the panel line by line and will even adjust when the panel width changes.

The final code:

5 5 votes
Article Rating
Notify of

1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
11 months ago

You are a genius, thank you so so much, this is AWESOME AND VERY SMART!