[pygtk] How to align entries in a table?

Steve McClure smcclure at racemi.com
Fri Jan 27 21:39:18 WST 2006


On Fri, 2006-01-27 at 08:13 -0500, Steve McClure wrote:
> On Thu, 2006-01-26 at 23:43 +0100, Sandro Dentella wrote:
> > Hi all,
> > 
> >    I'd like to understand how to align entry in a table  so that it will be
> >    "anchored" to the left. I can't find a way, not even using glade. The
> >    idea is that while creating a mask to input data I'd like each entry to
> >    be large no more than the allowed chars (I see that that's  possible using
> >    widht-chars if the container is a table, not if the container is VBox),
> >    and further I'd like to anchor the entry to the write, while I only get
> >    it in the center.
> > 
> >         city:  [     large entry       ]
> >     zip code:  [5chars]
> > 
> > 
> >    what I get instead is:
> > 
> >         city:  [     large entry       ]
> >     zip code:           [5chars]
> > 
> >     Which is the normal way to get this?
> 
> I use a GtkAlignment for that, but it looks quite a bit different in
> glade-2.  In 1.X you could anchor alignment children anywhere you
> wanted. As far as the the entry widget size, I've never been able to get
> it to be the right size.  AFAICT, in glade-2 you have to add an
> alignment widget from the widget popup menu, it isn't in the palette.

I just tried Gazpacho and it will let you set the width of the field in
characters. It isn't exact, but then I'm using a proportional font.
However, I don't see how to do the alignment that you want there either.

This is on Fedore Core 3, Gazpacho 0.5.3, GTK 2.4.14, PyGTK 2.4.1.

> 
> > 
> > 
> >     TIA
> >     sandro
> >     *:-)
> > 
> > 
> > 
> > 
> > 
> > class SampleWindow(gtk.Window):
> >     def __init__(self):
> >         gtk.Window.__init__(self)
> > 
> >         self.connect("delete_event", lambda a, b: gtk.main_quit())
> > 
> >         table = gtk.Table()
> >         self.add(table)
> > 
> >         city = gtk.Label("city: ")
> >         city.set_alignment(1.0, 0.5)
> >         ecity = gtk.Entry()
> > 
> >         lzip = gtk.Label("zip code: ")
> >         lzip.set_alignment(1, 0.5)
> >         ezip = gtk.Entry()
> >         ezip.set_property('width-chars',5)
> > 
> >         table.attach(city,0,1,0,1)
> >         table.attach(ecity,1,2,0,1)
> >         table.attach(lzip,0,1,1,2)
> >         table.attach(ezip,1,2,1,2,xoptions=gtk.SHRINK)
> > 
-- 
Steve McClure                                     Racemi
email: smcclure at racemi.com                        380 Interstate North Pkwy, SE
voice: 404-892-5850                               Suite 250
fax: 404-892-7215                                 Atlanta, GA 30339
                                                  http://www.racemi.com



More information about the pygtk mailing list