Setting sizes of widgets (PyGTK)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harlin Seritt

    #1

    Setting sizes of widgets (PyGTK)

    I have the following code and I would like to know how to set the
    length and width of widgets like Buttons. When the window opens the
    button fills up the space even though I have told it not to. Anyone
    know how I can accomplish this?

    :

    import pygtk, gtk

    class Greeter:

    def __init__(self):

    self.window = gtk.Window(gtk. WINDOW_TOPLEVEL )
    self.box = gtk.VBox()
    self.window.add (self.box)

    self.label = gtk.Label("Plea se enter your name in the box below:")
    self.namebox = gtk.Entry(12)
    self.button = gtk.Button("Gre et Me!")
    self.output = gtk.Label("Your output will appear here.")

    self.box.pack_s tart(self.label , False, False, 2)
    self.box.pack_s tart(self.nameb ox, False, False, 2)
    self.box.pack_s tart(self.butto n, False, False, 2)
    self.box.pack_s tart(self.outpu t, False, False, 2)

    self.label.show ()
    self.namebox.sh ow()
    self.button.sho w()
    self.output.sho w()
    self.box.show()
    self.window.sho w()

    def main(self):
    gtk.main()

    a = Greeter()
    a.main()

  • Franck Pommereau

    #2
    Re: Setting sizes of widgets (PyGTK)

    Harlin Seritt wrote:[color=blue]
    > I have the following code and I would like to know how to set the
    > length and width of widgets like Buttons. When the window opens the
    > button fills up the space even though I have told it not to.[/color]

    Your button is stretched horizontally because there is nothing to put
    around it in order to fill the space. Try to embed it into a HBox,
    surrounded by empty labels :
    [color=blue]
    > import pygtk, gtk
    >
    > class Greeter:
    > def __init__(self):
    > self.window = gtk.Window(gtk. WINDOW_TOPLEVEL )
    > self.box = gtk.VBox()
    > self.window.add (self.box)
    > self.label = gtk.Label("Plea se enter your name in the box below:")
    > self.namebox = gtk.Entry(12)
    > self.button = gtk.Button("Gre et Me!")
    > self.output = gtk.Label("Your output will appear here.")[/color]
    hbox = gtk.HBox()[color=blue]
    > self.box.pack_s tart(self.label , False, False, 2)
    > self.box.pack_s tart(self.nameb ox, False, False, 2)[/color]
    hbox.add(gtk.La bel())
    hbox.pack_start (self.button, False, False, 2)
    hbox.add(gtk.La bel())
    self.box.pack_s tart(hbox, False, False, 2)[color=blue]
    > self.box.pack_s tart(self.outpu t, False, False, 2)[/color]
    self.window.sho w_all()[color=blue]
    > def main(self):
    > gtk.main()
    >
    > a = Greeter()
    > a.main()[/color]

    Cheers,
    Franck

    Comment

    Working...