使用 Glade 快速编写一个简单的 GUI,我正在尝试创建一个通用错误对话框,我可以在其中将标签的文本设置为任何错误。在典型的 GUI 开发中非常简单(获取子表单、设置标签的标题属性等)。
不过,我似乎无法弄清楚如何在 PyGTK/Glade 中控制该标签。
这是我的对话框的 XML...
<object class="GtkMessageDialog" id="dError">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="message_type">error</property>
<property name="buttons">close</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lblError">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
这是我正在尝试的相关 Python 代码,尝试了 2 次。第一个我试图设置错误对话框的文本字段,第二个我添加了一个标签并尝试首先获取并设置它。
dError = self.builder_.get_object("dError") # get dialog
# Attempt 1 - setting the text field of the error dialog
# dError.set_text("Attempt 1")
#-- AttributeError: 'gtk.MessageDialog' object has no attribute 'set_text'
# Attempt 2 -setting an added label
# dLbl = dError.get_object("lblError")
#-- AttributeError: 'gtk.MessageDialog' object has no attribute 'get_object'
# dlbl.set_text("Attempt 2")
dError.show()
return True