Χάριν παραδείγματος:
- Κώδικας: Επιλογή όλων
# Load in pygtk and gtk
import pygtk
pygtk.require('2.0')
import gtk
import os
# Define the main window
class Whc:
def __init__(self):
# Window and framework
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.destroy)
# A Button, with an action
# Add it to the geometry
# show the button
self.button = gtk.Button("First Button")
self.button.connect("clicked", self.hello, None)
self.window.add(self.button)
self.button.show()
# Show the window
self.window.show()
# Callback function for use when the button is pressed
def hello(self, widget, data=None):
print "Hello World"
os.system("speaker-test -c 6 -t wav")
# Destroy method causes appliaction to exit
# when main window closed
def destroy(self, widget, data=None):
gtk.main_quit()
# All PyGTK applicatons need a main method - event loop
def main(self):
gtk.main()
if __name__ == "__main__":
base = Whc()
base.main()
Πηγή: http://www.wellho.net/resources/ex.php4 ... 2/hwpgt.py