无法在GTK中垂直打包按钮

2024-03-28 20:54:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把这两个按钮垂直地放在盒子里,为什么不管用? 这是我的密码。在

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

Tags: selfboxtruehellogtkinitbuttonwindow
1条回答
网友
1楼 · 发布于 2024-03-28 20:54:13

创建self.box,一个垂直方向的框,然后立即用另一个完全不同的、间距为6的新框(以及默认的水平方向)覆盖它。相反,要这样做

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

相关问题 更多 >