GtkSource模块不在Python中导入

时间:2015-01-30 23:22:37

标签: python gtk gtksourceview

我正在尝试使用python和gtk构建源代码编辑器,并且在运行脚本时出现以下错误:

AttributeError:'gi.repository.Gtk'对象没有属性'Source'

下面是我的代码,我在Homebrew上安装了所有依赖项(我已经研究过),但我仍然无法导入Gtk.sourceview。

# UI
# Imort modules
import os,sys,pygtk
from gi.repository import Gtk, Vte, GLib
from gi.repository import GObject
from gi.repository import GtkSource



class MainWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self)
        # Window title and Icon
        self.set_title("MaeTrics")
        # Vertical Box
        self.box = Gtk.VBox(homogeneous=False, spacing=0)
        self.add(self.box)
        # Scrolled Text Window
        scrolledwindow1 = Gtk.ScrolledWindow()
        scrolledwindow1.set_hexpand(True)
        scrolledwindow1.set_vexpand(True)
        # Source View
        self.source = Gtk.Source.View()
        self.buffer = self.source.get_buffer()
        self.source.set_show_line_numbers(True)
        scrolledwindow1.add(self.source)
        # Pack everything in vertical box
        self.box.pack_start(scrolledwindow1, True, True, 0)
        # Callback functions
        self.connect("delete-event", Gtk.main_quit)
        self.show_all()



window = MainWindow()
Gtk.main()

1 个答案:

答案 0 :(得分:3)

应该是

self.source = GtkSource.View()

这适用于我的Debian