窗口无法正常显示

时间:2013-07-16 18:59:04

标签: python pygtk glade

我有一个小问题,我无法解决有关使用gtk构建的窗口的问题:

在我的程序中,我有两个函数显示一个单独的gtk.window,其中包含内容(一个带有按钮 - 显示文本 - 另一个带有按键事件 - 显示matplotlib图 - )。在程序的第一次运行时,两个窗口正确显示我要求的内容,但当我关闭单独的窗口并尝试再次显示它时,我获得一个空窗口(在这两种情况下)我无法弄清楚为什么!

如果您有一些建议,我会很高兴看到它们(我将在我的程序的一个小版本上进行测试并稍后将其添加到帖子中。)

谢谢!

编辑:这是我测试的样本,我认为出现同样的问题,林间空地文件不多(一个窗口和两个按钮),但当我点击其中一个按钮时,第一次窗口是正常,当我关闭并重新打开时,我遇到了与我的真实程序相同的问题。

import gtk
import gtk.glade

class Testwin:
    # Initialisation of window and connection of signals
    def __init__(self):
        self.Main = gtk.Builder()
        self.Main.add_from_file('Testwin.glade')

        self.Mainwindow = self.Main.get_object("Main_window")
        self.Main.connect_signals(self)

        self.extWindow1 = self.Main.get_object("External_window1")
        self.extWindow2 = self.Main.get_object("External_window2")


    def on_window_destroy(self, widget):
        gtk.main_quit()

    def display_window1(self, widget):
        self.extWindow1.show_all()        

    def display_window2(self, widget):
        self.extWindow2.show_all()        


if __name__ == "__main__":
    Testwin()
    gtk.main()

(我也放了.glade文件,以防有人想测试它)

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <requires lib="gtk+" version="2.24"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="External_window1">
    <property name="can_focus">False</property>
    <child>
      <placeholder/>
    </child>
  </object>
  <object class="GtkWindow" id="External_window2">
    <property name="can_focus">False</property>
    <child>
      <placeholder/>
    </child>
  </object>
  <object class="GtkWindow" id="Main_window">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <signal name="destroy" handler="on_window_destroy" swapped="no"/>
    <child>
      <object class="GtkHButtonBox" id="hbuttonbox1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <object class="GtkButton" id="button1">
            <property name="label" translatable="yes">button</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="display_window2" swapped="no"/>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkButton" id="button2">
            <property name="label" translatable="yes">button</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="clicked" handler="display_window1" swapped="no"/>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">False</property>
            <property name="position">1</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

0 个答案:

没有答案