#!/usr/bin/env python # example_of_common_buttons.py # Note: This program only displays buttons, it does not connect signals to them. import pygtk pygtk.require('2.0') import gtk class Widgets: def destroy(self, widget, data=None): gtk.main_quit() def __init__(self): self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.destroy) v_box = gtk.VBox(False,30) # NORMAL buttons normal_button1 = gtk.Button("Normal Button One") normal_button2 = gtk.Button("Normal Button Two") normal_button1.show() normal_button2.show() # Pack normal buttons into a horizontal box h_box1 = gtk.HBox(False,10) h_box1.pack_start(normal_button1,False,False,0) h_box1.pack_start(normal_button2,False,False,0) # RADIO buttons - packing must be done throughout defining the buttons h_box2 = gtk.HBox(False,10) # radio 1 radio_button = gtk.RadioButton(None, "Radio One") radio_button.set_active(True) h_box2.pack_start(radio_button,False,False,0) radio_button.show() #radio 2 radio_button = gtk.RadioButton(radio_button, "Radio Two") h_box2.pack_start(radio_button,False,False,0) radio_button.show() #radio 3 radio_button = gtk.RadioButton(radio_button, "Radio Three") h_box2.pack_start(radio_button,False,False,0) radio_button.show() # CHECKLIST buttons checklist1 = gtk.CheckButton("Check Box One") checklist2 = gtk.CheckButton("Check Box Two") checklist1.show() checklist2.show() # Add checklist buttons to horizontal box h_box3 = gtk.HBox(False,10) h_box3.pack_start(checklist1,False,False,0) h_box3.pack_start(checklist2,False,False,0) # TOGGLE normal buttons toggle1 = gtk.ToggleButton("Toggle Button One") toggle2 = gtk.ToggleButton("Toggle Button Two") toggle1.show() toggle2.show() # Add checklist buttons to horizontal box h_box4 = gtk.HBox(False,10) h_box4.pack_start(toggle1,False,False,0) h_box4.pack_start(toggle2,False,False,0) # Pack normal button box into Vertical box v_box.pack_start(h_box1,False,False,0) # Pack radio button box into Vertical box v_box.pack_start(h_box2,False,False,0) # Pack checklist button box into Vertical box v_box.pack_start(h_box3,False,False,0) # Pack toggle button box into Vertical box v_box.pack_start(h_box4,False,False,0) # All remaining widgets that haven't been shown must be! self.window.add(v_box) h_box1.show() h_box2.show() h_box3.show() h_box4.show() v_box.show() self.window.show() def main(self): gtk.main() print __name__ if __name__ == "__main__": examples = Widgets() examples.main()