如何将Python程序从gtk2移植到gtk3?

2024-06-02 05:07:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我们正在尝试将this program从gtk2移植到gtk3。当我尝试pygi-convert.sh时,我遇到了以下错误:

Traceback (most recent call last):
  File "scripts/amir", line 53, in <module>
    from gi.repository import GObject
  File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 39, in <module>
    raise ImportError(_static_binding_error)
ImportError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183

对这个港口有什么建议或其他方法吗?在


Tags: infromimportrepositorylinestaticthisprogram
1条回答
网友
1楼 · 发布于 2024-06-02 05:07:14

首先,试着理解你在做什么。阅读official Python for GTK+ 3 tutorial的基础知识。您将看到导入的正确顺序是:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

pygi-convert.sh不是什么灵丹妙药,你必须了解这些变化并加以回顾。例如,this section中的导入肯定是错误的。顺序不正确,import gtk,Gtk.glade行上还有一个import gtk。一个git grep -w gtk应该可以帮助您找到代码中所有小写的gtk,这些应该被删除或替换。在

我还看到在同一个文件中有一些代码可以更改窗口主题。主题在GTK+2和GTK+3之间完全改变。GTK+3使用CSS引擎。在

查看Python GTK+ 3 API以了解可用的内容,并查看C迁移指南(不知道有python资源,抱歉)what has changed between GTK+ 2 and GTK+ 3。大多数东西不适用于python,但有些会。例如,在执行自定义绘图或检查哪些小部件已被终止和替换时,从旧的expose-event迁移到draw信号。在

然后试着跑,修正错误,冲洗,重复。在

相关问题 更多 >