本文介绍了将林间空地接口放在python中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在林间空地上制作了一个gui,我想放入python程序.我正在根据网上找到的教程中的说明进行调整,以将其加载到林间空地文件(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在工作,我之前没有使用林间空地就做了一些事情,而且效果很好.我收到的错误是:

I've made a gui in glade that I want to put in a python program. I was adapting the instructions from a tutorial I found online to load in my glade file (http://www.pygtk.org/articles/pygtk-glade-gui/Creating_a_GUI_using_PyGTK_and_Glade.htm). When I had problems I tried something basic (one button) calling it the same thing as in that tutorial, and copy pasting their code, and it still didn't work. I also took a look at (http://www.linuxjournal.com/article/6586?page=0,2), which has a function being called slightly differently ("self.wTree=gtk.glade.XML (gladefile,windowname)" instead of without windowname), and implemented an equivalent with mine and that didn't fix it. I definitely have pygtk working, I made something without using glade before and it worked fine. The error I'm getting is:

/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配置问题,但是如果相关,我会提供它.这是我从教程中获取的代码(但不起作用)

I'm running xubuntu 11.04. The Murrine configuration thing comes up when any gtk application opens, but I included it in case it is relevant. Here's the code I took from the tutorial (but isn't working)

#!/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()

推荐答案

尝试以下代码:

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

import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade

class HellowWorldGTK:

    def __init__(self):
        self.gladefile = "helloworld.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

记住:在Glade中,将文件的首选项"编辑为" GTKBuilder "(不是"libglade")

Remember:In Glade, Edit the "Preferences" of the file to "GTKBuilder" (not "libglade")

这篇关于将林间空地接口放在python中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 07:54