[pygtk] manipulate image from a gtk.Button
awalter1
alain.walter at thalesgroup.com
Thu Nov 29 03:54:10 WST 2007
Hi,
I had thought to check the "gtk-button-images" property, that was set to
True (in fact it is the default value).
Thank you for the customization of my button.
Concerning version of gtk+, I am going to plan the installation of the last
one
Bye
Augusto Rocca... wrote:
>
> El día Tue, 27 Nov 2007 08:29:02 -0800 (PST)
> awalter1 <alain.walter at thalesgroup.com> escribió:
>
>>
>> I have tried your complete example.
>> A small window is displayed without image in the button.
>> May be our environment are too different :
>> unix 11.11 on HPUX
>> python 2.4.2
>> gtk+ 2.6.9
>
> Yes, too different:
> linux 2.6.23 / python 2.5.1 / gtk+ 2.12.1 / pygtk 2.12.0
>
> Anyway .set_image() method is available in pygtk 2.6 and above[0], (I
> suppose
> you have =>pygtk-2.6)
> May be you must check that "gtk-button-images" property is True.
> (Available in
> GTK+2.4 and above)
>
>>>> settings = button.get_settings()
>>>> settings.get_property("gtk-button-images")
> True
>
>> >From the time being I'm using this procedure, that seems to work
>> correctly
>>
>> self.optionButton = gtk.Button(stock=gtk.STOCK_ADD)
>> SetlabelToButton(self.optionButton,gtk.STOCK_ADD)
>> ...
>> def SetlabelToButton(button, stock_item=None,label=None):
>> if (stock_item != None):
>> button.set_label(stock_item)
>> alignment = button.get_children()[0]
>> hboxtemp = alignment.get_children()[0]
>> image, text = hboxtemp.get_children()
>> if (label != None):
>> text.set_text(label)
>> else:
>> text.set_text('')
>
> And as a last option you can write your own custom button.
>
> # only work when we set stock item via constructor
> class CustomButtom(gtk.Button):
> def __init__(self, stock=gtk.STOCK_ADD):
> gtk.Button.__init__(self, stock)
> def set_image_or_label(self, stock_item=None, label=None):
> if stock_item:
> self.set_label(stock_item)
> al = self.get_children()[0]
> hb = al.get_children()[0]
> image, text = hb.get_children()
> if label:
> text.set_text(label)
> else:
> text.set_text('')
>
> [0]http://www.moeraki.com/pygtkreference/pygtk2reference/class-gtkbutton.html#method-gtkbutton--set-image
>
> Excuse me for my english!
> Best Regards
> --Augusto
> _______________________________________________
> 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/
>
>
--
View this message in context: http://www.nabble.com/manipulate-image-from-a-gtk.Button-tf4880483.html#a14007774
Sent from the Gtk+ - Python mailing list archive at Nabble.com.
More information about the pygtk
mailing list