[pygtk] image and text in button
Chris Lambacher
chris at kateandchris.net
Tue Jan 23 06:37:41 WST 2007
On Mon, Jan 22, 2007 at 09:35:14PM +0100, Yann Le Boulanger wrote:
> I attached a very simple exemple that adds text and an image in a
> button. This code works under linux (evert GTK version) but not under
> windows (GTK2.10.6 / pygtk2.10.3). Ttext is displayed, but not image.
>
> Do I use button badly or is it a win32 bug ?
Try swapping the image load and adding to the button:
import gtk
w = gtk.Window()
b = gtk.Button()
i = gtk.Image()
i.set_from_file('asterix.png')
b.set_image(i)
b.set_label('')
w.add(b)
w.show_all()
gtk.main()
It has been a long time since I have tried to manually load an Image into a
button. Eventually you will want to get into creating a gtk.IconSet for each
icon you want to use and then create an gtk.IconFactory which you add your
IconSets to with a stock_id that you make up. Then you add you IconFactory
to the default stock icon search list by calling gtk.IconFactory.add_default
(see http://pygtk.org/docs/pygtk/class-gtkiconfactory.html). This has the
added advantage that you integrate nicely with UIManager for creating toolbars
and menus.
-Chris
>
> --
> Yann
> import gtk
>
> w = gtk.Window()
> b = gtk.Button()
> i = gtk.Image()
> b.set_image(i)
> b.set_label('')
> i.set_from_file('asterix.png')
> w.add(b)
> w.show_all()
> gtk.main()
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
More information about the pygtk
mailing list