2013-02-10 54 views
1

我想將兩個按鈕垂直打包在框中,爲什麼它不起作用? 這是我的代碼。無法在GTK中垂直打包按鈕

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() 

回答

5

創建self.box,與垂直方向的盒子,然後立即用另一覆蓋它,完全不一樣,與間隔6個新的框(和默認的水平方向)。而不是

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