#!/usr/bin/env python # example_of_packing_widgets.py import pygtk pygtk.require('2.0') import gtk class Widgets: def destroy(self, widget, data=None): gtk.main_quit() def kill_window(self,widget): widget.destroy() def button_clicked(self, widget, data): self.window1 = gtk.Window(gtk.WINDOW_TOPLEVEL) label = gtk.Label("blah") label.set_text("You clicked on button "+data+"!!!") label.show() self.window1.add(label) self.window1.connect("destroy", self.kill_window) self.window1.show() def __init__(self): # table self.window1 = gtk.Window(gtk.WINDOW_TOPLEVEL) # When the X at the top right of a window is clicked, a destroy # signal is sent to the window widget. From here the window # can decide what to do, if anything, in response to the signal. self.window1.connect("destroy", self.destroy) #buttons normal_button1=gtk.Button("button one") normal_button1.connect("clicked",self.button_clicked,"one") normal_button2=gtk.Button("button two") normal_button2.connect("clicked",self.button_clicked,"two") normal_button3=gtk.Button("button three") normal_button3.connect("clicked",self.button_clicked,"three") normal_button4=gtk.Button("button four") normal_button4.connect("clicked",self.button_clicked,"four") normal_button1.show() normal_button2.show() normal_button3.show() normal_button4.show() # Table table = gtk.Table(rows=2, columns=2, homogeneous=False) table.set_row_spacings(30) table.set_col_spacings(10) # (button, top left, top right, bottom upper, bottom lower) table.attach(normal_button1, 0, 1, 0, 1) #Top Left table.attach(normal_button2, 1, 2, 0, 1) #Top Right table.attach(normal_button3, 0, 1, 1, 2) #Bottom Left table.attach(normal_button4, 1, 2, 1, 2) #Bottom Right self.window1.add(table) # Show all table.show() self.window1.show() def main(self): gtk.main() print __name__ if __name__ == "__main__": examples = Widgets() examples.main()