我已经制作了一个gui,我想放在python程序中。我正在修改我在网上找到的教程中的说明,以加载我的glade文件(http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm)。当我遇到问题时,我尝试了一些基本操作(一个按钮),并将其称为与该教程中相同的内容,并复制粘贴它们的代码,但仍然无效。我也看了一下(http://www.linuxjournal.com/article/6586?page=0.2),它有一个稍微不同的函数调用(“self.wTree = gtk.glade.XML(gladefile, windowname)“,而不是没有windowname),并实施了与我的等价物,但没有解决它。我绝对有pygtk工作,我做了一些没有使用glade之前,它工作正常。我得到的错误是:在python中放置glade界面
/usr/share/themes/NOX/gtk-2.0/gtkrc:233: Murrine configuration option "gradients"
is no longer supported and will be ignored.
(helloWorld.py:9804): libglade-WARNING **: Expected <glade-interface>. Got
<interface>.
(helloWorld.py:9804): libglade-WARNING **: did not finish in PARSER_FINISH state
Traceback (most recent call last):
File "helloWorld.py", line 31, in <module>
hwg = HellowWorldGTK()
File "helloWorld.py", line 22, in __init__
self.wTree = gtk.glade.XML(self.gladefile)
RuntimeError: could not create GladeXML object
我正在运行xubuntu 11.04。当任何gtk应用程序打开时,Murrine配置就会出现,但我将它包括在内以防相关。这里是我从教程中获取的代码(但不工作)
#!/usr/bin/env python
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
class HellowWorldGTK:
"""This is an Hello World GTK application"""
def __init__(self):
#Set the Glade file
self.gladefile = "PyHelloWorld.glade"
self.wTree = gtk.glade.XML(self.gladefile)
#Get the Main Window, and connect the "destroy" event
self.window = self.wTree.get_widget("MainWindow")
self.window.show()
if (self.window):
self.window.connect("destroy", gtk.main_quit)
if __name__ == "__main__":
hwg = HellowWorldGTK()
gtk.main()
这回答了你的问题:http://stackoverflow.com/questions/2668618/python-glade-could-not-create-gladexml-object – dumbmatter
谢谢:)。它现在有效。 – Harpy
看看这个链接http://techaffairs.com.br/corrigindo-problema-libglade%E2%88%92warning-expected-glade%E2%88%92interface-got-interface/在这篇文章中,你将能够得到代码示例,这篇文章是用葡萄牙语。 – 2012-02-23 14:00:02