为什么我的窗口中不显示笔记本控件?

1 投票
1 回答
1188 浏览
提问于 2025-04-16 04:52

虽然我对Python不算陌生,但这是我第一次尝试用Glade来设计界面。我的Python文件是这样的:

import gobject
import gtk
import gtk.glade

class prefs_dialog:

    def __init__ (self):

        # Initialize the dialog

        self.window = gtk.glade.XML("file.glade").get_widget("prefs_dialog")
        self.window.show()

pd = prefs_dialog()
gtk.main()

而“file.glade”文件是这样的:

<?xml version="1.0"?>
<glade-interface>
  <!-- interface-requires gtk+ 2.16 -->
  <!-- interface-naming-policy project-wide -->
  <widget class="GtkDialog" id="prefs_dialog">
    <property name="border_width">5</property>
    <property name="type_hint">normal</property>
    <property name="has_separator">False</property>
    <child internal-child="vbox">
      <widget class="GtkVBox" id="dialog-vbox">
        <property name="visible">True</property>
        <property name="spacing">2</property>
        <child>
          <widget class="GtkNotebook" id="notebook1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <child>
              <placeholder/>
            </child>
            <child>
              <widget class="GtkLabel" id="label1">
                <property name="visible">True</property>
                <property name="label" translatable="yes">page 1</property>
              </widget>
              <packing>
                <property name="tab_fill">False</property>
                <property name="type">tab</property>
              </packing>
            </child>
            <child>
              <placeholder/>
            </child>
            <child>
              <widget class="GtkLabel" id="label2">
                <property name="visible">True</property>
                <property name="label" translatable="yes">page 2</property>
              </widget>
              <packing>
                <property name="position">1</property>
                <property name="tab_fill">False</property>
                <property name="type">tab</property>
              </packing>
            </child>
            <child>
              <placeholder/>
            </child>
            <child>
              <widget class="GtkLabel" id="label3">
                <property name="visible">True</property>
                <property name="label" translatable="yes">page 3</property>
              </widget>
              <packing>
                <property name="position">2</property>
                <property name="tab_fill">False</property>
                <property name="type">tab</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child internal-child="action_area">
          <widget class="GtkHButtonBox" id="dialog-action_area">
            <property name="visible">True</property>
            <property name="layout_style">end</property>
            <child>
              <placeholder/>
            </child>
            <child>
              <placeholder/>
            </child>
          </widget>
          <packing>
            <property name="expand">False</property>
            <property name="pack_type">end</property>
            <property name="position">0</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>

当我运行这个应用程序时,出现了一个非常小的窗口,并且显示了这个信息:

python prefs_dialog.py
prefs_dialog.py:11: GtkWarning: gtk_notebook_set_tab_label: assertion `GTK_IS_WI
DGET (child)' failed
  self.window = gtk.glade.XML("file.glade").get_widget("prefs_dialog")

另外,控件也没有显示出来。

1 个回答

2

好的,看起来问题出在笔记本控制器的标签里没有任何小工具。添加了一些东西后,控制器终于显示出来了。

撰写回答