[pygtk] Label a different font sizes
Neil Dugan
pygtk at butterflystitches.com.au
Sat Apr 19 11:54:40 WST 2008
Vláďa wrote:
> Thank you for your reply. I know I have to use "set_use_markup(True)".
> All of the Pango markup attributes work for me except of font size. At
> the top of the page you are referring there is an example:
>
> <span foreground="blue" size="100">Blue text</span>
>
> So I think my code is correct. The problem is, that the first value
> (size="14") in my example is also used for the second line, although I
> specified new size (size="10"). The strange thing is that if I use
> attributes like "large" or "small" then it works. Unfortunately my
> English is rather weak, so I'm not sure if I can explain it clearly.
> Here is a short sample code to show the problem:
>
I used the line
self.label = gtk.Label('<span
size="20000">Texting</span>\n<span size="15000">Texting</span>\n<span
size="small">Text 3</span>')
Everything worked how it should
Ubuntu 7.10 (gutsy)
Gnome 2.10.1
Kernel 2.6.22-14-generic
Python 2.5.1
Regards Neil.
> #!/usr/bin/env python
> import pygtk
> pygtk.require('2.0')
> import gtk
> import pango
>
> class HelloWorld:
> def hello(self, widget, data=None):
> print "Hello World"
>
> def delete_event(self, widget, event, data=None):
> print "delete event occurred"
> return False
>
> def destroy(self, widget, data=None):
> print "destroy signal occurred"
> gtk.main_quit()
>
> def __init__(self):
> self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
> self.window.connect("delete_event", self.delete_event)
> self.window.connect("destroy", self.destroy)
> self.window.set_border_width(10)
> self.button = gtk.Button()
> self.label = gtk.Label('<span size="20">Text 1</span>\n<span
> size="10">Text 2</span>\n<span size="small">Text 3</span>')
> self.label.set_use_markup(True)
> self.button.add(self.label)
> self.button.connect("clicked", self.hello, None)
> self.button.connect_object("clicked", gtk.Widget.destroy,
> self.window)
> self.window.add(self.button)
> self.window.show_all()
>
> def main(self):
> gtk.main()
>
> if __name__ == "__main__":
> hello = HelloWorld()
> hello.main()
>
> The button label has 3 lines, the first 2 have size 14, the last one is
> small. But the second line should have size 10. What is wrong in my code?
>
> Thank you
>
>
> John Finlay napsal(a):
>
>> Vláďa wrote:
>>
>>> Hi,
>>>
>>> I have a question regarding labels and Pango.
>>>
>>> I want to use different sizes of font, but unfortunately it doesn't
>>> work. If I use
>>>
>>> self.label = gtk.Label('<span size="14">Text 1</span>\n<span
>>> size="10">Text 2</span>')
>>>
>>> then only the first size definition (14) is taken into account. The
>>> second line has the same font size.
>>>
>>> Is this a feature, bug or my fault? Hot to create a label with
>>> different font sizes in it?
>>
>> First you have to tell the label to use Pango markup:
>>
>> self.label.set_use_markup(True)
>>
>> Then you have to specify a readable size since numerical sizes are in
>> thousandths of a point - see:
>>
>> http://www.pygtk.org/docs/pygtk/pango-markup-language.html
>>
>> John
>>
> _______________________________________________
> 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/
>
More information about the pygtk
mailing list