#!/usr/bin/env python3 import gi import mpv import locale gi.require_version('Gtk', '3.0') from gi.repository import Gtk locale.setlocale(locale.LC_NUMERIC, 'C') 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() entry_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) self.add(entry_container) self.entry_box = Gtk.Entry() entry_container.pack_start(self.entry_box, True, True, 0) play_button = Gtk.Button(label="Start") play_button.connect("clicked", self.on_play) entry_container.pack_start(play_button, True, True, 1) exit_btn = Gtk.Button(label="Exit") exit_btn.connect("clicked", self.on_destroy) entry_container.pack_start(exit_btn, True, True, 2) # ~ self.add(play_button) self.add(widget) self.show_all() # ~ @self.mpv.on_key_press('q') # ~ def my_q_binding(): # ~ print('THERE IS NO ESCAPE') # ~ self.mpv.terminate() def on_play(self, widget): # Must be created >after< the widget is shown, else property 'window' will be None self.mpv = mpv.MPV(wid=str(widget.get_property("window").get_xid()), ytdl=True, input_default_bindings=True, input_vo_keyboard=True, osc=True) input_media = self.entry_box.get_text() self.mpv.play(input_media) self.mpv.wait_for_playback() self.mpv.terminate() def on_destroy(self, widget, data=None): #self.mpv.terminate() Gtk.main_quit() if __name__ == '__main__': application = MainClass() Gtk.main()