To embed mpv in a GTK window, pass the XID of the widget to the wid parameter.
CRITICAL: Similar to PyQT, you must call locale.setlocale(locale.LC_NUMERIC, 'C') after importing Gtk but before creating the first mpv.MPV instance.
Note: The MPV instance must be created after the widget is shown, otherwise the window property may be None.
import gi
import mpv
import locale
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class MainClass(Gtk.Window):
def __init__(self):
super(MainClass, self).__init__()
self.set_default_size(600, 400)
self.connect("destroy", self.on_destroy)
widget = Gtk.Frame()
self.add(widget)
self.show_all()
# Must be created after widget is shown
self.mpv = mpv.MPV(wid=str(widget.get_property("window").get_xid()))
self.mpv.play("test.webm")
def on_destroy(self, widget, data=None):
self.mpv.terminate()
Gtk.main_quit()
if __name__ == "__main__":
# Required: Fix locale before creating MPV instance
locale.setlocale(locale.LC_NUMERIC, 'C')
application = MainClass()
Gtk.main()