FAQ Index - Search - Recent Changes - Everything - Add entry

<< Previous Entry | FAQ Entry 4.1 | Next Entry >>

4.1. How do I change font properties on gtk.Labels and other widgets?

Easy:

 label = gtk.Label("MyLabel")
 label.modify_font(pango.FontDescription("sans 48"))
This method applies to all widgets that use text, so you can change the text of gtk.Entry and other widgets in the same manner.

Note that, some widgets are only containers for others, like gtk.Button. For those you'd have to get the child widget. For a gtk.Button do this:

  if button.get_use_stock():
     label = button.child.get_children()[1]
  elif isinstance(button.child, gtk.Label):
     label = button.child
  else:
     raise ValueError("button does not have a label")

PyGTK FAQ Wizard | PyGTK Homepage | Feedback to faq at pygtk.org