Search code examples
pythonsocketsgtkgtk3

Using GTK3 Socket For Embedding Window in Another Window (Python)


I want to embed a window in GTK window by using socket. I have found an example, changed it to run by using GTK3, but it did not work. It gives following error:

AttributeError: 'gi.repository.Gtk' object has no attribute 'Socket'

It needs X11 platform but are there any solutions to use it on Windows?

Software Information: Python: 3.8.6, GTK3, Windows 10 (x64).

Code:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
import string
import sys

# Some code here

socket = Gtk.Socket()
socket.show()
window1.add(socket)
print("Socket ID=", socket.get_id())
window1.connect("destroy", Gtk.main_quit)

def plugged_event(widget):
    print("I (",widget,") have just had a plug inserted!")

socket.connect("plug-added", plugged_event)

if len(sys.argv) == 2:
    socket.add_id(long(sys.argv[1]))

builder.connect_signals(Signals())
window1.show_all()
Gtk.main()

Solution

  • GtkPlug and GtkSocket at X11-only widgets, and do not work on any other windowing system/platform.