DrawingArea Cannot Get XID

前端 未结 1 1485
灰色年华
灰色年华 2021-01-07 01:39

I have the following Python 2.7/PyGObject 3.0/PyGST 0.10 module:

from gi.repository import Gtk, Gdk, GdkPixbuf
import pango
import pygst
pygst.require(\'0.10         


        
相关标签:
1条回答
  • 2021-01-07 02:17

    (Reprinted from GNOME PyGObject 3 Bug Report 663360. Answer credit goes to Timo Vanwynsberghe).

    There are a couple of things to note: - the drawingarea has to be realised before you can get its GdkWindow - apparently, you can't get the window property directly - you need to import GdkX11 for the xid method

    With this in mind, here is a minimal working example:

    from gi.repository import GdkX11, Gtk
    
    class App:
        def __init__(self):
            win = Gtk.Window()
            win.resize(400, 400)
            win.connect('delete-event', Gtk.main_quit)
    
            da = Gtk.DrawingArea()
            win.add(da)
            win.show_all()
    
            print da.get_property('window').get_xid()
    
    if __name__ == "__main__":
        App()
        Gtk.main()
    
    0 讨论(0)
提交回复
热议问题