[pygtk] gtk.label + wrapping

Laszlo Pandy laszlok2 at gmail.com
Sun Feb 1 06:42:22 WST 2009


http://library.gnome.org/devel/gtk/stable/GtkLabel.html#gtk-label-set-line-wrap

"Note that setting line wrapping to TRUE does not make the label wrap at
its parent container's width, because GTK+ widgets conceptually can't
make their requisition depend on the parent container's size. For a
label that wraps at a specific position, set the label's width using
gtk_widget_set_size_request()."

If you want the label to wrap at a specific position do:
>>> l = gtk.Label()
>>> l.set_line_wrap(True)
>>> l.set_size_request(500, -1) # make 500 pixels wide.

If you don't use a specific size, the label will use the default width,
but there is no way that I know of to make it rewrap dynamically when it
is resized. In many cases you would use a TextArea to do this instead.

Laszlo

On Fri, 2009-01-30 at 19:33 +0100, Yann Leboulanger wrote:
> Hi guys,
> 
> I have a gtk.Label, filled with a long text. I enabled wrap on this
> label, so that text is splitted into several lines.
> 
> The problem is that when I increase window width, the wrapping is not
> re-computed.
> 
> I tried to set_line_wrap() to False then True every 2 seconds, but still
> it's not re-computed.
> I tried to re-set text every 2 seconds, but still it's not re-computed.
> I tried to set_max_width_chars(-1) every 2 seconds, but still it's not
> re-computed.
> I tried to set_property('width-chars', -1) every 2 seconds, but still
> it's not re-computed.
> 
> I have no more ideas. Is it doable without using a textview (which don't
> look the same way at all)?



More information about the pygtk mailing list