I modified some old pygtk-1 code I found for adding an pixmap to a button, but the image doesn't display correctly in the button
Any ideas what is wrong, or if there is a better/easier way?
(code and pixmap below)
import pygtk
pygtk.require('2.0')
import gtk
def add_button_icon_pixmap(button, pixmap, orientation='left'):
button.realize()
label = gtk.Label(button.get_children()[0].get())
button.remove(button.get_children()[0])
if orientation is None:
box = gtk.HBox(spacing=0)
box.pack_start(pixmap, gtk.FALSE, gtk.FALSE, 0)
if orientation in ('left', 'right'):
box = gtk.HBox(spacing=5)
elif orientation in ('top', 'bottom'):
box = gtk.VBox(spacing=5)
if orientation in ('left', 'top'):
box.pack_start(pixmap, gtk.FALSE, gtk.FALSE, 0)
box.pack_start(label, gtk.FALSE, gtk.FALSE, 0)
elif orientation in ('right', 'bottom'):
box.pack_start(label, gtk.FALSE, gtk.FALSE, 0)
box.pack_start(pixmap, gtk.FALSE, gtk.FALSE, 0)
hbox = gtk.HBox()
if box is not None:
hbox.pack_start(box, gtk.TRUE, gtk.FALSE, 0)
hbox.show_all()
button.add(hbox)
def add_button_icon(button, file, orientation='left'):
button.realize()
window = button.get_parent_window()
xpm, mask = gtk.create_pixmap_from_xpm(window, None, file)
pixmap = gtk.Image()
pixmap.set_from_pixmap(xpm, mask)
add_button_icon_pixmap(button, pixmap, orientation)
win = gtk.Window()
win.show()
button = gtk.Button('Click Me')
button.show()
win.add(button)
add_button_icon(button, 'stock_video-24.xpm', None)
gtk.mainloop()
<<attachment: stock_video-24.xpm>>
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
