【问题标题】:GtkSource module not importing in PythonGtkSource 模块未在 Python 中导入
【发布时间】:2015-01-30 23:22:36
【问题描述】:

我正在尝试使用 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()

【问题讨论】:

  • 那是什么? Gtk.Source.View 还是 GtkSource.View?
  • 重新检查您的文档,这看起来不正确,并且错误说明很多。

标签: python gtk gtksourceview


【解决方案1】:

应该是

self.source = GtkSource.View()

这在 Debian 上适用于我

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-06
    • 2018-02-02
    相关资源
    最近更新 更多