简体   繁体   中英

How do i import gtk module to my application? python

dialog = gtk.FileChooserDialog("Open..",
                           None,
                           gtk.FILE_CHOOSER_ACTION_OPEN,
                           (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                            gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)

I want to use the above code for file browsing- but when I give the following import

import pygtk
pygtk.require('2.0')

import gtk

I get Error: No module named 'pygtk'

Do I need to give pygtk as a module inside my application folder? Do say with steps. Thank you.

pygtk is the old and deprecated gtk Python api. Do not use it unless you have a legacy application. The correct way nowadays is to use GObject-introspection to use Gtk3 from Python. Which is also really awesome as it makes Python a first-class supported language, with no wrappers necessary.

from gi.repository import Gtk
dlg = Gtk.FileChooserDialog()
dlg.show()

You should look at this: http://rox.sourceforge.net/desktop/node/245.html

It shows some problems. Good luck on fixing it :).

Edit:

测试PyGTK安装

This has lots of info on pip install (windows): How do I install pip on Windows?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM