【发布时间】:2017-08-06 23:05:51
【问题描述】:
我正在学习 GTK+3 教程,并且我学习过的所有示例——以及我使用代码和 glade 编写的代码——都会产生一个比必要更大的窗口。
有没有人对我做错了什么有什么建议,或者如何解决它?
这是一个简单的例子:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title = 'Hello World')
self.box = Gtk.Box(spacing=6)
self.add(self.box)
self.button1 = Gtk.Button(label = 'Hello')
self.button1.connect('clicked', self.on_button1_clicked)
self.box.pack_start(self.button1, True, True, 0)
self.button2 = Gtk.Button(label = 'Goodbye')
self.button2.connect('clicked', self.on_button2_clicked)
self.box.pack_start(self.button2, True, True, 0)
def on_button1_clicked(self, widget):
print('Hello')
def on_button2_clicked(self, widget):
print('Goodbye')
win = MyWindow()
win.connect('delete-event', Gtk.main_quit)
win.show_all()
Gtk.main()
这是我的代码产生的结果:
根据教程,这是它应该看起来的样子
【问题讨论】:
-
可以指点教程吗?
-
另外,我应该提一下,如果我手动将窗口调整为尽可能小的尺寸,它看起来就像示例一样。我编写的其他程序也是如此。只是当我输入显示的代码时,窗口每次都显得过大,而不是占用内容所需的最少空间。
标签: python python-2.7 gtk3