[pygtk] set_use_markup and gtk.Button

Art Hunkins abhunkin at uncg.edu
Sun Aug 9 09:42:06 WST 2009


Thanks, John. This was exactly the solution I needed.

And a wonderful opportunity for me (a newbee writing a Sugar/SoaS Activity) 
to learn about child widgets and containers.

Art Hunkins

----- Original Message ----- 
From: "John Finlay" <finlay at moeraki.com>
To: "Art Hunkins" <abhunkin at uncg.edu>
Cc: <pygtk at daa.com.au>
Sent: Friday, August 07, 2009 7:03 PM
Subject: Re: [pygtk] set_use_markup and gtk.Button


> 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 



More information about the pygtk mailing list