Python Gtk+ development in Linux using Eclipse + P

2019-08-13 19:28发布

I just tried to write my first Gtk+ program using python in linux mint with Eclipse + PyDev, but I met this error in PyDev, Unresolved import: Gtk

program source code: http://python-gtk-3-tutorial.readthedocs.org/en/latest/introduction.html

from gi.repository import Gtk

win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

error shown as below:

enter image description here

Program can run. I checked PYTHONPATH in PyDev, I think it's right. enter image description here

How can I fix this problem?

By the way, could you give some advice about nice free IDE for Python & Gtk+ development in Linux?

3条回答
放荡不羁爱自由
2楼-- · 2019-08-13 19:51

Go to Window->Preferences and add "gi" to "Forced Builtins" (see screenshots).
You should try Glade for GTK3 gui design (see screenshot).
See final result screenshot.
You could also use Sublime Text 3.

enter image description here

enter image description here

enter image description here

enter image description here enter image description here

查看更多
相关推荐>>
3楼-- · 2019-08-13 19:52

You must use Python 3.x.

Eclipse->Windows->Preferences->PyDev->Python Interpreter*->Advanced Auto-Config->/usr/share/python3.3**->Ok->Apply->Ok

*If using Python, instead of Jython or IronPython

**If Python 3.3 installed, otherwise try python3, but I've not tested.

查看更多
Ridiculous、
4楼-- · 2019-08-13 20:07

same issue: https://stackoverflow.com/a/11418828/1040891

In Gtk+ 3 Python bindings to binary modules are generated dynamically using *.typelib databases. The dynamic importer for accessing all the modules is located in gi.repository. PyCharm cannot detect these modules using its code insight, because they require special handling.

Note: IPython can detect and handle these modules

查看更多
登录 后发表回答