Art Hunkins wrote: > I have been happily using the set_use_markup property of gtk.Label and > gtk.Frame with XML markup, to create bolded, italic and various sized text. > > I need to do this with gtk.Button as well - to do the same with (callback) > button labels. However, I've not been able. I've employed the two general > approaches below (with results immediately below them): > > #1: > > def cbbutton(self,box,callback,title=""): > """Creates a callbackbutton > box: parent box > callback: click callback > title: if given, the button name > returns the widget instance""" > self.cbbutts = self.cbbutts + 1 > label = gtk.Label(title) > label.set_use_markup(True) > butt = gtk.Button(" %s " % label) > box.pack_start(butt, False, False, 5) > self.cbbuttons.append([butt,label,0]) > butt.connect("clicked", callback) > butt.show() > return butt > > The above version runs fine, but gives unwanted button labels, of this > variety: > <gtk.Label object a 0x[....] (GtkLabel at 0x[....different])> > > > #2: > > def cbbutton(self,box,callback,title=""): > """Creates a callbackbutton > box: parent box > callback: click callback > title: if given, the button name > returns the widget instance""" > self.cbbutts = self.cbbutts + 1 > label = gtk.Label() > label.set_markup(title) > butt = gtk.Button() > butt.child = label > label.show() > box.pack_start(butt, False, False, 5) > self.cbbuttons.append([butt,label,0]) > butt.connect("clicked", callback) > butt.show() > return butt > > The above version crashes, with the following error log: > > /usr/lib/python2.6/site-packages/sugar/activity/main.py:35: GtkWarning: > gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || > GTK_IS_INVISIBLE (widget)' failed > activity.show() > Gtk:ERROR:gtkwidget.c:7967:gtk_widget_real_map: assertion failed: > (GTK_WIDGET_REALIZED (widget)) > > Can someone please suggest what changes might give me a proper label? > > FWIW, including XML tags in "title" makes no difference whatever in the > above results. > > How about:
butt = gtk.Button(title) butt.child.set_use_markup(True) John _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/