Search code examples
pythonimportintrospectiongtk3

Importing Gtk object from gi.repository


Back in my GTK2 days, I could do a

from gtk import Clipboard

To get access to the clipboard from my program.

Now days, we must import objects introspectively as in:

from gi.repository import Gtk

I have been scratching my head to see if there is a way to import just an object from Gtk like:

from gi.repository import Gtk.Clipboard

of course this results in a SyntaxError exception.

Is there a way to do what I'm trying to do? One reason I would like this right now, is that I need a very light way to access the clipboard for a script. I don't want to import all of Gtk, as it is overboard/overkill. I just want the Clipboard class, but I'm curious for other items in the gi.repository (like Notify).

Thanks,

Narnie


Solution

  • Very easily.

    from gi.repository.Gtk import Clipboard