[Tutor] Fonts for Canvas text items ?

Michael P. Reilly arcege@shore.net
Sun, 11 Feb 2001 13:35:44 -0500 (EST)


> Python 2.0 and Windows 98
> 
> To find out how to change the font for a text item on a Canvas, I tried
> the following code. But the only effect I get is on the size of the
> font. The larger size appears in the first three lines, the tiny size in
> the last line.
> 
> How can I get different fonts, different thickness, different size ?

I don't know about Win98, but you can get the list of fonts with
  Python 2.0 (#3, Dec 18 2000, 02:47:55)
  [GCC 2.96 20000731 (Red Hat Linux 7.0)] on linux2
  Type "copyright", "credits" or "license" for more information.
  >>> import tkFont
  >>> tkFont.families()
  ('fangsong ti', 'fixed', 'clearlyu alternate glyphs', 'charter',
  'lucidatypewriter', 'lucidabright', 'times', 'lucidux sans',
  'open look glyph', 'song ti', 'zapf dingbats', 'avantgarde',
  'helvetica', 'open look cursor', 'newspaper', 'mincho',
  'clearlyu ligature', 'lucidux mono', 'clearlyu pua', 'palatino',
  'courier', 'clearlyu', 'lucida', 'utopia', 'clean', 'nil',
  'terminal', 'zapf chancery', 'cursor', 'symbol', 'gothic',
  'bookman', 'lucidux serif', 'new century schoolbook',
  'clearlyu arabic extra')
  >>> root = tkFont.Tkinter.Tk()
  >>> f = tkFont.Font(root, ('courier', 10, tkFont.NORMAL))
  >>> tkFont.Tkinter.Label(root, text='hi', font=f).pack()

You should be able to set fonts with Font instances.

  -Arcege

PS: Your example worked fine on my systems.

> 
> from Tkinter import *
> 
> Wurzel=Tk()
> 
> Leinwand = Canvas(Wurzel)
> 
> Leinwand.create_text(50,50,text="Helvetica",font="Helvetica")
> Leinwand.create_text(50,100,text="NewCourier",font="NewCourier")
> Leinwand.create_text(50,150,text="bold",font="bold")
> Leinwand.create_text(50,200,text="no font")
> 
> Leinwand.pack()
> 
> Wurzel.mainloop()

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------