Label text does not span width of container



Hello,

I have a simple program with a label on the main window.

I place some text in the label and set the 'set_line_wrap' property of the label to True.

However, when I run the script I notice that the text in the label does not span the entire width of the window, as there are left and right borders of space surrounding the label's text.

How do I alter the properties of the label so that the rendered text in the label spans the entire width of the parent window/container?

I have tried using a v/hbox without success, and experimenting with glade and various container configurations yields the same outcome.

I do not want to alter the width of the window to match the width of the rendered text, but would prefer to have the width of the rendered text meet the left and right edges of the window (thereby also reducing the number of lines of text).

Removing the 'set_line_wrap(True)' directive for the label creates a label with a single line and stretches the parent window beyond the limits of the screen to accomodate the text in the label - something that is not desirable.

I would like the text of the label to meet the left and right edges of the parent window/container if possible.

Any assistance will be appreciated.


#!/usr/bin/env python

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

class dislabel:
  def __init__(self):
       self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
       self.window.connect("destroy", lambda w: gtk.main_quit())

       self.window.set_title("Label with   set_line_wrap ( True )")
       self.window.set_size_request(600, 200)

       dastring = "I am feeling somewhat claustrophobic as "\
       +"there are vertical borders of empty space to the "\
       +"right and left of this label, even though this "\
       +"label has been assigned the value set_line_wrap (True)."\
       +" How do I remove these annoying spaces and have "\
       +"the text of the label span the entire width "\
       +"of the window/container?"

       label = gtk.Label(dastring)
label.set_line_wrap(True)

       self.window.add(label)

       self.window.show_all ()

def main():
  gtk.main()
  return 0

if __name__ == "__main__":
  dislabel()
  main()




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]