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

发布于 2024-09-26 10:26:48 字数 4340 浏览 7 评论 0原文

虽然我对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")

此外,控件不显示。

Although I am not new to Python, this is my first attempt at using Glade to design the interface. My Python file looks like this:

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

And the "file.glade" file looks like this:

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

When I run the application, I get a really tiny window and the message:

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")

Also, the control does not show.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

调妓 2024-10-03 10:26:48

好吧,问题似乎是笔记本控件的选项卡中没有小部件。添加一些东西导致控件最终出现。

Okay, so it seems like the problem is that the notebook control had no widgets in the tabs. Adding something caused the control to finally show up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文