0
使用Glade快速編寫簡單的GUI,我試圖創建一個通用的錯誤對話框,我可以將標籤的文本設置爲任何錯誤。在典型的GUI開發中非常簡單(獲取子表單,設置標籤的標題屬性等)。在Glade/PyGTK對話窗口中設置標籤
我似乎無法弄清楚如何在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>
這裏是我想,有2次嘗試相關的Python代碼。第一次我試圖設置錯誤對話框的文本字段,第二次我添加了一個標籤,並嘗試先獲取並設置該標籤。
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
謝謝!像魅力一樣工作 – espais