为什么笔记本控件没有显示在我的窗口中? [英] Why is the notebook control not showing up in my window?

查看:66
本文介绍了为什么笔记本控件没有显示在我的窗口中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我对 Python 并不陌生,但这是我第一次尝试使用 Glade 来设计界面.我的 Python 文件如下所示:

导入gobject进口gtk导入gtk.glade类 prefs_dialog:def __init__ (self):# 初始化对话框self.window = gtk.glade.XML("file.glade").get_widget("prefs_dialog")self.window.show()pd = prefs_dialog()gtk.main()

file.glade"文件如下所示:

<glade界面><!-- 界面-需要 gtk+ 2.16 --><!-- 项目范围内的接口命名策略--><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><孩子><widget class="GtkNotebook" id="notebook1"><property name="visible">True</property><property name="can_focus">True</property><孩子><占位符/></孩子><孩子><widget class="GtkLabel" id="label1"><property name="visible">True</property><property name="label" translatable="yes">第 1 页</property></小部件><包装><property name="tab_fill">False</property><property name="type">tab</property></包装></孩子><孩子><占位符/></孩子><孩子><widget class="GtkLabel" id="label2"><property name="visible">True</property><property name="label" translatable="yes">第2页</property></小部件><包装><property name="position">1</property><property name="tab_fill">False</property><property name="type">tab</property></包装></孩子><孩子><占位符/></孩子><孩子><widget class="GtkLabel" id="label3"><property name="visible">True</property><property name="label" translatable="yes">page 3</property></小部件><包装><property name="position">2</property><property name="tab_fill">False</property><property name="type">tab</property></包装></孩子></小部件><包装><property name="position">1</property></包装></孩子><child internal-child="action_area"><widget class="GtkHButtonBox" id="dialog-action_area"><property name="visible">True</property><property name="layout_style">end</property><孩子><占位符/></孩子><孩子><占位符/></孩子></小部件><包装><property name="expand">False</property><property name="pack_type">end</property><property name="position">0</property></包装></孩子></小部件></孩子></小部件></glade-interface>

当我运行应用程序时,我看到一个非常小的窗口和消息:

<前>python prefs_dialog.pyprefs_dialog.py:11: GtkWarning: gtk_notebook_set_tab_label: 断言`GTK_IS_WIDGET(子)'失败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.

解决方案

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.

这篇关于为什么笔记本控件没有显示在我的窗口中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆