showkey
showkey

Reputation: 348

Can't pack buttons vertically in GTK

I want to pack the two buttons vertically in the box, why doesn't it work? Here is my code.

from gi.repository import Gtk
class MyWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Hello World")
        self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.box = Gtk.Box(spacing=6)
        self.add(self.box)
        self.button1 = Gtk.Button(label="Hello")
        self.box.pack_start(self.button1, True, True, 0)
        self.button2 = Gtk.Button(label="Goodbye")
        self.box.pack_start(self.button2, True, True, 0)


win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

Upvotes: 2

Views: 1864

Answers (1)

ptomato
ptomato

Reputation: 57850

You create self.box, a box with vertical orientation, then immediately overwrite it with another, completely different, new box with spacing 6 (and the default horizontal orientation). Instead do

self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)

Upvotes: 7

Related Questions