Reputation: 73
I'm trying to get buttons with image and label and didn't succed. I can have button with label OR image but not both. This is my part of code:
try:
pb = Pixbuf.new_from_file_at_size('myimg.jpg', 100, 100)
except:
pb = None
img = Gtk.Image()
img.set_from_pixbuf(pb)
button1 = Gtk.Button(xalign=0.5, yalign=1)
#button1.set_label(lbl)
button1.set_image(img)
button1.set_image_position(Gtk.PositionType.TOP)
button1.get_style_context().add_class("btn_article")
any idea ? Thanks
Upvotes: 3
Views: 3899
Reputation: 1195
Doc: Gtk.Button.set_image (widget, data): "The image will be displayed if the label text is NULL". The image here usually is an icon, therefore there is a icon-name associate with it and (depends on settings) if necessary showing the label according the icon. Reverse the situation, the label is used to find an icon associate with it and (if necessary) showing the icon. Use:
button1.set_always_show_image (True)
or, if that doesn't succeed, create a container inside (in your case Gtk.Grid) and pack inside the button, i.e:
grid = Gtk.Grid ()
img = Gtk.Image()
img.set_from_pixbuf(pb)
label = Gtk.Label ('test')
grid.attach (img, 0, 0, 1, 1)
grid.attach (label, 0, 1, 1, 1)
grid.show_all ()
button1.add (grid)
Upvotes: 8