#!/usr/bin/env python # example-start buttons buttons.c import gtk # Create a new hbox with an image and a label packed into it # and return the box. def xpm_label_box(parent, xpm_filename, label_text): # Create box for xpm and label box1 = gtk.GtkHBox(gtk.FALSE, 0) box1.set_border_width(2) # Get the style of the button to get the # background color. style = parent.get_style() # Now on to the xpm stuff pixmap, mask = gtk.create_pixmap_from_xpm(parent.get_window(), style.bg[gtk.STATE_NORMAL], xpm_filename) pixmapwid = gtk.GtkPixmap(pixmap, mask) # Create a label for the button label = gtk.GtkLabel(label_text) # Pack the pixmap and label into the box box1.pack_start(pixmapwid, gtk.FALSE, gtk.FALSE, 3) box1.pack_start(label, gtk.FALSE, gtk.FALSE, 3) pixmapwid.show() label.show() return box1 class Buttons: # Our usual callback method def callback(self, widget, data=None): print "Hello again - %s was pressed" % data def __init__(self): # Create a new window self.window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL) self.window.set_title("Pixmap'd Buttons!") # It's a good idea to do this for all windows. self.window.connect("destroy", gtk.mainquit) self.window.connect("delete_event", gtk.mainquit) # Sets the border width of the window. self.window.set_border_width(10) self.window.realize() # Create a new button button = gtk.GtkButton() # Connect the "clicked" signal of the button to our callback button.connect("clicked", self.callback, "cool button") # This calls our box creating function box1 = xpm_label_box(self.window, "info.xpm", "cool button") # Pack and show all our widgets button.add(box1) box1.show() button.show() self.window.add(button) self.window.show() def main(): gtk.mainloop() return 0 if __name__ == "__main__": Buttons() main()