Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么笔记本控件没有显示在我的窗口中?_Python_Pygtk_Glade - Fatal编程技术网

Python 为什么笔记本控件没有显示在我的窗口中?

Python 为什么笔记本控件没有显示在我的窗口中?,python,pygtk,glade,Python,Pygtk,Glade,虽然我对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

虽然我对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()
<?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>
“file.glade”文件如下所示:

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()
<?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>

5.
正常的
假的
真的
2.
真的
真的
真的
第1页
假的
标签
真的
第2页
1.
假的
标签
真的
第3页
2.
假的
标签
1.
真的
结束
假的
结束
0
当我运行应用程序时,我会看到一个非常小的窗口和消息:

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") python prefs_dialog.py prefs_dialog.py:11:GtkWarning:gtk_notebook_set_tab_label:assertion`gtk_IS_WI DGET(子项)“”失败 self.window=gtk.glade.XML(“file.glade”).get_小部件(“prefs_对话框”)
另外,该控件没有显示。

好的,所以问题似乎是笔记本控件的选项卡中没有小部件。添加某些内容导致控件最终显示