当我在Glade(程序)中构建这个相同的ui时,生成的代码是完美无缺的,当我手工编写代码时,除了一件事之外,一切都有效,set_position(670)被忽略,结果窗口出现在大约1&# 34;我屏幕上的广场。
我的目标是让左侧窗格以670像素宽度实现。我并不担心锁定宽度。
我尝试过调用set_position(670):
self.top.show_all()
self.top.show_all()
pack1
后搜索谷歌导致没有有用的结果,到目前为止我找不到有用的答案。
pyGtk网站表明该呼叫几乎可以放在任何地方。 gtk网站没有列出任何限制。 我发现的大多数东西似乎表明它是由于其他一个小部件的resize / shrink属性,但是经过多次尝试改变左侧窗格中所有内容的值后,我仍然感到茫然。 (请注意,一次尝试一次或两次更改值。)
import gtk
import gobject
class Source(gobject.GObject):
def _emit_signal(self, button, value):
self.emit('choice_changed', self, value)
def __init__(self):
self.__gobject_init__()
# packing treee
# top
# main
# inst_align
# inst_window
# instructions
# opt_align
# opt_buttons
# opt_0 (through opt_5)
# doit_box
# doit
self.top = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
self.main = gtk.HPaned()
self.main.set_position(670)
self.top.add(self.main)
# Build left side components
self.inst_align = gtk.Alignment(0.0, 0.0, 1.0, 1.0)
self.inst_window = gtk.ScrolledWindow(None, None)
self.inst_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.instructions = gtk.TextView(None)
self.instructions.get_buffer().set_text(
"Very long (1200 char) string snipped.")
#pack pane 1
self.inst_window.add(self.instructions)
self.inst_align.add(self.inst_window)
self.main.pack1(self.inst_align, True, False)
# build right side components
self.opt_align = gtk.Alignment(1.0, 0.0, 0.0, 0.0)
self.opt_buttons = gtk.VButtonBox()
self.opt_buttons.set_layout(gtk.BUTTONBOX_START)
self.opt_buttons.set_homogeneous(True)
self.opt_0 = gtk.RadioButton(
None,
"Label 0",
True)
self.opt_1 = gtk.RadioButton(
self.opt_0,
"Label 1",
True)
self.opt_2 = gtk.RadioButton(
self.opt_0,
"Label 2",
True)
self.opt_3 = gtk.RadioButton(
self.opt_0,
"label 3",
True)
self.opt_4 = gtk.RadioButton(
self.opt_0,
"Label 4",
True)
self.opt_5 = gtk.RadioButton(
self.opt_0,
"Label 5",
True)
self.doit_box = gtk.HButtonBox()
self.doit = gtk.Button("Do It !", None, True)
self.doit.expand = False
self.doit.fill = False
self.doit.set_alignment(0.5, 0.0)
# Put the buttons in the box and while were at it, bind their
# released, and pressed options
for i in range(0, 6):
s = "self.opt_" + str(i)
self.opt_buttons.pack_start( eval(s), True, False, 0 )
s1 = s + '.connect("released", self._emit_signal, i)'
s2 = s + '.connect("pressed", self._emit_signal, i)'
exec(s1)
exec(s2)
self.doit_box.pack_start(self.doit, True, False, 0)
self.opt_buttons.pack_start(self.doit_box, True, False, 0)
self.opt_align.add(self.opt_buttons)
self.main.pack2(self.opt_align, True, False)
self.top.show_all()
gobject.type_register(Source)
gobject.signal_new('choice_changed',
Source,
gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, (Source, gobject.TYPE_INT))
if __name__ == "__main__":
def cb_test(widget, event, value):
print "widget is", widget
print "Value is ", value
return
test = Source()
win = gtk.Window()
win.add(test.top)
win.show_all()
test.connect('choice_changed', cb_test)
gtk.main()
答案 0 :(得分:0)
您必须设置一个大于HPane分隔符位置的窗口。这是一个精简的例子:
import gtk
class Source(gtk.Window):
def __init__(self):
super(Source, self).__init__()
label1 = gtk.Label("The first label")
label2 = gtk.Label("The second label")
paned = gtk.HPaned()
paned.add1(label1)
paned.add2(label2)
paned.set_position(600)
self.add(paned)
self.set_size_request(800, 400) # needs sufficient width here
self.connect('delete-event', gtk.main_quit)
self.show_all()
if __name__ == "__main__":
test = Source()
gtk.main()