在 Python 2 中,使用我的机器(Ubuntu 12.10)中安装的内容,我可以做到
import gtk
cb = gtk.clipboard_get()
content = cb.wait_for_text()
从剪贴板中获取文本。
然而,在 Python3 中,我应该对 Gtk.Clipboard() 对象做同样的事情,但是我得到了一些似乎与小部件和类似的东西有关的错误,但是我的应用程序没有 GUI 并且不应该. 我在正确的轨道上吗?
>>> from gi.repository import Gtk
>>> cb = Gtk.Clipboard()
>>> content = cb.wait_for_text()
/usr/lib/python3/dist-packages/gi/types.py:47: Warning: g_object_get_data: assertion `G_IS_OBJECT (object)' failed
return info.invoke(*args, **kwargs)
(.:10935): Gdk-CRITICAL **: gdk_display_get_default_screen: assertion `GDK_IS_DISPLAY (display)' failed
(.:10935): Gtk-CRITICAL **: gtk_invisible_new_for_screen: assertion `GDK_IS_SCREEN (screen)' failed
/usr/lib/python3/dist-packages/gi/types.py:47: Warning: invalid (NULL) pointer instance
return info.invoke(*args, **kwargs)
/usr/lib/python3/dist-packages/gi/types.py:47: Warning: g_signal_connect_data: assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
return info.invoke(*args, **kwargs)
(.:10935): Gtk-CRITICAL **: gtk_widget_add_events: assertion `GTK_IS_WIDGET (widget)' failed
/usr/lib/python3/dist-packages/gi/types.py:47: Warning: g_object_set_data: assertion `G_IS_OBJECT (object)' failed
return info.invoke(*args, **kwargs)
/usr/lib/python3/dist-packages/gi/types.py:47: Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed
return info.invoke(*args, **kwargs)
(.:10935): Gdk-CRITICAL **: gdk_display_get_default_screen: assertion `GDK_IS_DISPLAY (display)' failed
(.:10935): Gtk-CRITICAL **: gtk_invisible_new_for_screen: assertion `GDK_IS_SCREEN (screen)' failed
(.:10935): Gtk-CRITICAL **: gtk_widget_add_events: assertion `GTK_IS_WIDGET (widget)' failed
(.:10935): Gtk-CRITICAL **: gtk_widget_get_window: assertion `GTK_IS_WIDGET (widget)' failed
(.:10935): Gtk-CRITICAL **: gtk_selection_convert: assertion `GTK_IS_WIDGET (widget)' failed