[pygtk] Centering widgets horizontally on screen
saeed
saeed.gnu at gmail.com
Wed Aug 26 08:42:15 WST 2009
That's related to packing, not WIN_POS_CENTER! (that's position of
window on the screen!)
See gtk.Box.pack_start
def pack_start(child, expand=True, fill=True, padding=0)
I assume you should use expand=True, fill=False
Also you may need to use an empty label gtk.Label('') with packing expand=True
for example, for your first questtion:
_________________________________
#!/usr/bin/python
import gtk
b1 = gtk.Button('Button1')
b2 = gtk.Button('Button2')
b3 = gtk.Button('Button3')
b4 = gtk.Button('Button4')
hbox = gtk.HBox()
hbox.pack_start(b1, True, False)
hbox.pack_start(b2, True, False)
hbox.pack_start(b3, True, False)
hbox.pack_start(b4, True, False)
win = gtk.Window()
win.add(hbox)
win.show_all()
gtk.main()
_______________________________
Now run the script and resize the window to see the result.
If you want to remove spaces between button, use two empty label (in
the beginning and the end of box):
_______________________________
#!/usr/bin/python
import gtk
b1 = gtk.Button('Button1')
b2 = gtk.Button('Button2')
b3 = gtk.Button('Button3')
b4 = gtk.Button('Button4')
hbox = gtk.HBox()
hbox.pack_start(gtk.Label(''), True, False)
hbox.pack_start(b1, False, False)
hbox.pack_start(b2, False, False)
hbox.pack_start(b3, False, False)
hbox.pack_start(b4, False, False)
hbox.pack_start(gtk.Label(''), True, False)
win = gtk.Window()
win.add(hbox)
win.show_all()
gtk.main()
__________________________________
I assume this is what you wish.
About second question, no different between button or hbox or another
widget. You should only understand packing options and behavior.
On 8/26/09, Art Hunkins <abhunkin at uncg.edu> wrote:
> Another newbee question (or two):
>
> I've no problem centering text in the middle of the screen, but otherwise
> don't know how to do the same with buttons and Hboxes. Hence:
>
> 1) how to center a group of 4 buttons horizontally?
>
> 2) how to center a nested (packed) set of boxes horizontally?
>
> I assume gtk.Window and gtk.WIN_POS_CENTER are involved, but that's about
> all I "know."
>
> Art Hunkins
>
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
>
More information about the pygtk
mailing list