Automatic Line breaks on Everything

How do I have automatic line breaks on everything (Labels, Button, Grids, etc). I am using Python

Care to explain what “automatic line breaks” are, and in which context are you expecting them?

Instead of
xxxxxxxxxxxxxxxx…
it will be
xxxx
xxxx
xxxx

Are you asking how to wrap the contents of a GtkLabel? In which case, you should look at the wrap property.

And, how do I do that for Grids, that were populated with 114 items using a loop.

If you’re packing labels into a grid, you need to set the “wrap” property on each label.

Grid have no idea what a “line break” is.

Incidentally, if you’re putting 100+ labels in a grid you’re most likely doing something weird.

I am putting buttons in it. Those are the chapters from a Book like the Bible.

Then you’ll have to access the label inside each GtkButton, and set the wrap property on it.

Alternatively, you can construct each GtkButton yourself and pack a GtkLabel into it that has the wrap property set.

I did that and it still does this.


It is going off my screen and, it takes too much time to pull and find the close button (I have to close it with ^D in the terminal.
I want it to fill the screen by creating new lines on it and make it scrollable. I can’t do the labels manually, it is too much. I am using an API to fetch the data.

Ah OK, that screenshot clarifies a lot.

You don’t want line breaks, you want a container that wraps its children according to the available space. GtkGrid doesn’t do that, it arranges its children in rows and columns that are specified by the programmer.

What you want instead is a container like GridView or FlowBox.

Now it is tall. I used FlowBox.

You can use the min-children-per-line and max-children-per-lin to control the width of the flow box.

Works perfectly now.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.