1from gi.repository import Gtk 2import sys 3 4# a Gtk ApplicationWindow 5 6 7class MyWindow(Gtk.ApplicationWindow): 8 # constructor: the title is "Welcome to GNOME" and the window belongs 9 # to the application app 10 11 def __init__(self, app): 12 Gtk.Window.__init__(self, title="Welcome to GNOME", application=app) 13 14 15class MyApplication(Gtk.Application): 16 # constructor of the Gtk Application 17 18 def __init__(self): 19 Gtk.Application.__init__(self) 20 21 # create and activate a MyWindow, with self (the MyApplication) as 22 # application the window belongs to. 23 # Note that the function in C activate() becomes do_activate() in Python 24 def do_activate(self): 25 win = MyWindow(self) 26 # show the window and all its content 27 # this line could go in the constructor of MyWindow as well 28 win.show_all() 29 30 # start up the application 31 # Note that the function in C startup() becomes do_startup() in Python 32 def do_startup(self): 33 Gtk.Application.do_startup(self) 34 35# create and run the application, exit with the value returned by 36# running the program 37app = MyApplication() 38exit_status = app.run(sys.argv) 39sys.exit(exit_status) 40