2

ボックスに 2 つのボタンを縦に並べたいのですが、うまくいきません。これが私のコードです。

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

1 に答える 1

7

self.box垂直方向のボックスを作成し、すぐに間隔 6 (およびデフォルトの水平方向) のまったく異なる別の新しいボックスで上書きします。代わりに

self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
于 2013-02-10T21:57:29.690 に答える