Blame platform-demos/C/samples/button.py
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
# a window
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="GNOME Button", application=app)
|
|
Packit |
1470ea |
self.set_default_size(250, 50)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a button
|
|
Packit |
1470ea |
button = Gtk.Button()
|
|
Packit |
1470ea |
# with a label
|
|
Packit |
1470ea |
button.set_label("Click me")
|
|
Packit |
1470ea |
# connect the signal "clicked" emitted by the button
|
|
Packit |
1470ea |
# to the callback function do_clicked
|
|
Packit |
1470ea |
button.connect("clicked", self.do_clicked)
|
|
Packit |
1470ea |
# add the button to the window
|
|
Packit |
1470ea |
self.add(button)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback function connected to the signal "clicked" of the button
|
|
Packit |
1470ea |
def do_clicked(self, button):
|
|
Packit |
1470ea |
print("You clicked me!")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = MyApplication()
|
|
Packit |
1470ea |
exit_status = app.run(sys.argv)
|
|
Packit |
1470ea |
sys.exit(exit_status)
|