mirror of
https://github.com/Apress/foundations-of-pygtk-development.git
synced 2025-08-03 10:11:12 +02:00
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import gi
|
|
gi.require_version('Gtk', '3.0')
|
|
from gi.repository import Gtk
|
|
|
|
class AppWindow(Gtk.ApplicationWindow):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.set_border_width(25)
|
|
button = Gtk.Button.new_with_mnemonic("_Close")
|
|
button.connect("clicked", self.on_button_clicked)
|
|
button.set_relief(Gtk.ReliefStyle.NORMAL)
|
|
self.add(button)
|
|
self.set_size_request(200, 100)
|
|
|
|
def on_button_clicked(self, button):
|
|
self.destroy()
|
|
|
|
class Application(Gtk.Application):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, application_id="org.example.myapp",
|
|
**kwargs)
|
|
self.window = None
|
|
|
|
def do_activate(self):
|
|
if not self.window:
|
|
self.window = AppWindow(application=self,
|
|
title="Hello World!")
|
|
self.window.show_all()
|
|
self.window.present()
|
|
|
|
if __name__ == "__main__":
|
|
app = Application()
|
|
app.run(sys.argv)
|