multiline gtk.Label ignores xalign=0.5

Posted by thomas on Stack Overflow See other posts from Stack Overflow or by thomas
Published on 2012-04-07T16:40:57Z Indexed on 2012/04/07 17:28 UTC
Read the original article Hit count: 326

Filed under:
|
|
|

A gtk.Label can't be aligned in center when line-wrap is turned on. Example code:

import pygtk
pygtk.require('2.0')
import gtk

class testwin(gtk.Window):
   def __init__(self):
      gtk.Window.__init__(self)
      width,height = 300,300
      self.set_size_request(width,height)
      self.set_position(gtk.WIN_POS_CENTER)
      self.set_title("test window")

      label = gtk.Label("test text")
      label.set_line_wrap(True)
      label.set_justify(gtk.JUSTIFY_CENTER)
      label.set_alignment(0.5,0.5)
      label.connect("size-allocate",lambda l,s: l.set_size_request(s.width-1, -1))

      self.add(label)
      self.connect("destroy", gtk.main_quit)
      self.show_all()

testwin()
gtk.main()

It looks like this, that means, it's aligned left: http://m45.img-up.net/?up=pic122x97.png

If you comment out line 14 (set_line_wrap) everything is perfectly fine: http://o54.img-up.net/?up=pic2y00p9.png

Please note that yalign works fine. So it seems like the first argument in the gtk.Misc.set_alignment-function has no effect when line wrap is turned on.

Using Fedora 16, 64bit, gtk 3.2.4, pygtk 2.24.0, python 2.7.2

Question: Is this intended or a bug? How is it supposed to be made or is a workaround available?

© Stack Overflow or respective owner

Related posts about label

Related posts about alignment