#!/usr/bin/env python import pygtk pygtk.require('2.0') import gtk,os,thread class BasicButtons(): def msg(self, widget, msg): print(msg + " was clicked") if msg == "Exit": self.destroy(widget) elif msg == "Get Files": thread.start_new_thread(self.list_files,("/media","Files:")) elif msg == "Print Files": for f in self.files: print(f) def list_files(self, dir, msg): print(msg) self.files = [] for root, dirnames, filenames in os.walk(dir): self.files += filenames def destroy(self, widget, data=None): print("Destroyed!") print("What a world!\nWhat a world!") gtk.main_quit() def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.destroy) self.window.set_border_width(10) self.window.set_size_request(720,480) self.window.set_position(gtk.WIN_POS_CENTER) self.window.set_title("My GTK Button Program") self.box = gtk.VBox() self.window.add(self.box) self.box.show() self.buttons = ['On','Off','Next','Prev', 'Get Files', 'Print Files', 'Exit'] for b in self.buttons: self.button = gtk.Button(b) self.button.connect("clicked", self.msg, b) self.box.pack_start(self.button) self.button.show() self.window.show() def main(self): gtk.main() if __name__ == "__main__": Buttons = BasicButtons() Buttons.main()