By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,450 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

Setting sizes of widgets (PyGTK)

P: n/a
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("Please enter your name in the box below:")
self.namebox = gtk.Entry(12)
self.button = gtk.Button("Greet Me!")
self.output = gtk.Label("Your output will appear here.")

self.box.pack_start(self.label, False, False, 2)
self.box.pack_start(self.namebox, False, False, 2)
self.box.pack_start(self.button, False, False, 2)
self.box.pack_start(self.output, False, False, 2)

self.label.show()
self.namebox.show()
self.button.show()
self.output.show()
self.box.show()
self.window.show()

def main(self):
gtk.main()

a = Greeter()
a.main()

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Harlin Seritt wrote:
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.
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 :
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("Please enter your name in the box below:")
self.namebox = gtk.Entry(12)
self.button = gtk.Button("Greet Me!")
self.output = gtk.Label("Your output will appear here.") hbox = gtk.HBox() self.box.pack_start(self.label, False, False, 2)
self.box.pack_start(self.namebox, False, False, 2) hbox.add(gtk.Label())
hbox.pack_start(self.button, False, False, 2)
hbox.add(gtk.Label())
self.box.pack_start(hbox, False, False, 2) self.box.pack_start(self.output, False, False, 2) self.window.show_all() def main(self):
gtk.main()

a = Greeter()
a.main()


Cheers,
Franck
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.