【发布时间】:2014-08-02 17:05:36
【问题描述】:
我正在使用 GTK3(来自 gi.repository)和 python3 创建一个 UI。当我将默认图标添加到 UI 并运行程序时,它会因同伴错误而崩溃:
segmentation fault (core dumped) python main.py
我正在使用 Gtk.Window 的set_icon_list 方法添加图标:
self.c_win.set_icon_list(icon_list)
如果我评论这一行,程序会按预期运行。我得到具有以下功能的图标列表:
def load_icon():
req = pkg_resources.Requirement.parse("pympress")
# If pkg_resources fails, load from directory
try:
icon_names = pkg_resources.resource_listdir(req, "share/pixmaps")
except pkg_resources.DistributionNotFound:
icon_names = os.listdir("share/pixmaps")
icons = []
for icon_name in icon_names:
if os.path.splitext(icon_name)[1].lower() != ".png":
continue
# If pkg_resources fails, load from directory
try:
icon_fn = pkg_resources.resource_filename(req, "share/pixmaps/{}".format(icon_name))
except pkg_resources.DistributionNotFound:
icon_fn = "share/pixmaps/{}".format(icon_name)
try:
icon_pixbuf = Pixbuf()
icon_pixbuf.new_from_file(icon_fn)
icons.append(icon_pixbuf)
except Exception as e:
print(e)
return icons
它返回一个 Pixbuf 列表,它是 set_icon_list 的预期输入。
完整代码可在 github 上找到:https://github.com/Jenselme/pympress 知道问题出在哪里吗?
【问题讨论】:
标签: python-3.x gtk3 pygobject