george young wrote:

On Wed, Nov 13, 2002 at 03:54:13PM +0800, James Henstridge wrote:

george young wrote:


[pygtk-1.99.13, gtk-2.1.1, python-2.2.1, linux]
I am just trying to set the font for a gtk.Entry. I tried:

import gtk
top = gtk.Window(gtk.WINDOW_TOPLEVEL)
top.show()
e = gtk.Entry()
sty = e.get_style().copy()
sty.font = gtk.load_font('fixed')
e.set_style(sty)
e.set_text('the rain')
e.show()
top.add(e)
gtk.mainloop()

but the font I get is some default, variable width font. What am
I doing wrong? [I *have* scoured the FAQ and mailing list archives...]



GTK 2.0 uses a new text layout system called Pango, which is why the old method of changing the font does not work.

If you want to change an entry field to a monospaced font, use the following:
font_desc = pango.FontDescription('monospace')
entry.modify_font(font_desc)


Whoa. Does this mean that the old commands *still work*, but produce old
results? George?

The above code just displays in the default font, seemingly ignoring
the set_style() statement. It doesn't crash, but I would say that's
"not working". It's not the "old results" one would have got from gtk+-1.x.

The reason that the font doesn't apply is that the GtkStyle class no longer has a font property (it was removed), so doing "style.font = foo" simply sets an attribute on the style object that isn't used for anything. The widget.modify_font() method of changing the font is preferred with gtk 2.0.

James.

--
Email: [EMAIL PROTECTED] | Linux.conf.au http://linux.conf.au/
WWW: http://www.daa.com.au/~james/ | Jan 22-25 Perth, Western Australia.


_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Reply via email to