The script shows minimal Python codes that are required for a GTK3 application. A button and a label are included to demonstrate how button event is handled.
Source Code
#!/usr/bin/python
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Hello World")
self.connect("delete-event", Gtk.main_quit)
self.set_default_geometry(width=400, height=200)
mBox = Gtk.VBox(2)
mButt = Gtk.Button(label="Click Here")
mButt.connect("clicked", self.on_button_clicked)
mBox.pack_start(mButt,True,True,2)
self.label = Gtk.Label("Message")
mBox.pack_start(self.label,True,True,2)
self.add(mBox)
def on_button_clicked(self, widget):
print("Hello World")
self.label.set_text("Hello World")
win = MyWindow()
win.show_all()
Gtk.main()

No comments:
Post a Comment