Glade 3使用Python无法正常工作

时间:2014-03-22 19:58:19

标签: python gtk glade

我与Glade 3 for Windows 7(v3.14.2)建立了良好的界面 它应该用Python运行Ubuntu 12.04

所以我做了这个程序:

#!/usr/bin/env python
# -*- coding: utf-8 -*-


import gtk
import gtk.glade

class HellowWorldGTK:

        def __init__(self):
                self.gladefile = "userInput.glade" 
                self.glade = gtk.Builder()
                self.glade.add_from_file(self.gladefile)
                self.glade.connect_signals(self)
                self.glade.get_object("mainWindow").show_all()

        def on_MainWindow_delete_event(self, widget, event):
                gtk.main_quit()

if __name__ == "__main__":
        try:
                a = HellowWorldGTK()
                gtk.main()
        except KeyboardInterrupt:
                pass

并且,当在Ubuntu中运行时,这就是控制台所说的:

aimc@ubuntu:~/Desktop$ python main_ex.py 
main_ex.py:13: GtkWarning: Unknown property: GtkWindow.margin-left
  self.glade.add_from_file(self.gladefile)
main_ex.py:13: GtkWarning: Unknown property: GtkWindow.margin-right
  self.glade.add_from_file(self.gladefile)
main_ex.py:13: GtkWarning: Unknown property: GtkWindow.margin-top
  self.glade.add_from_file(self.gladefile)
main_ex.py:13: GtkWarning: Unknown property: GtkWindow.margin-bottom
  self.glade.add_from_file(self.gladefile)
main_ex.py:13: Warning: cannot create instance of abstract (non-instantiatable) type `GtkPaned'
  self.glade.add_from_file(self.gladefile)
Segmentation fault (core dumped)

我的.glade文件有什么问题?我应该使用其他Glade版本吗? 我非常感谢你的帮助。

Glade File(它的一个片段,因为stackoverflow赢了,让我把它全部放完):

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <!-- interface-requires gtk+ 3.0 -->
  <object class="GtkAction" id="action1"/>
  <object class="GtkAction" id="action2"/>
  <object class="GtkActionGroup" id="actiongroup1"/>
  <object class="GtkImage" id="image1">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <property name="stock">gtk-go-forward</property>
  </object>
  <object class="GtkListStore" id="liststore1"/>
  <object class="GtkWindow" id="mainWindow">
    <property name="can_focus">False</property>
    <property name="margin_left">3</property>
    <property name="margin_right">3</property>
    <property name="margin_top">3</property>
    <property name="margin_bottom">3</property>
    <child>
      <object class="GtkPaned" id="paned1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <child>
          <object class="GtkPaned" id="paned2">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <child>
              <object class="GtkBox" id="box1">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="hexpand">True</property>
                <property name="resize_mode">immediate</property>
                <property name="orientation">vertical</property>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <object class="GtkButton" id="btnDrop">
                    <property name="label" translatable="yes">Drop</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <signal name="clicked" handler="clicked_drop" swapped="no"/>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <object class="GtkButton" id="btnReward">
                    <property name="label" translatable="yes">Reward</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <signal name="clicked" handler="clicked_reward" swapped="no"/>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">3</property>
                  </packing>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <object class="GtkButton" id="btnOpen">
                    <property name="label" translatable="yes">Open Valve</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">5</property>
                  </packing>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <object class="GtkButton" id="btnClose">
                    <property name="label" translatable="yes">Close Valve</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">7</property>
                  </packing>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <object class="GtkButton" id="btnStart">
                    <property name="label" translatable="yes">Start / Stop training</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">9</property>
                  </packing>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <object class="GtkButton" id="btnPause">
                    <property name="label" translatable="yes">Pause / Resume Training</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">11</property>
                  </packing>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <object class="GtkButton" id="btnExit">
                    <property name="label" translatable="yes">Exit</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <signal name="clicked" handler="gtk.main_quit" swapped="no"/>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">13</property>
                  </packing>
                </child>
              </object>
              <packing>

2 个答案:

答案 0 :(得分:0)

您可能在Windows和Ubuntu上有不同的,不兼容的GTK版本。

答案 1 :(得分:0)

我再次尝试使用Glade3.8(官方网站上提供的早期版本),它可以使用我上面编写的代码,并提供更丰富的RAD工具。