How to Write words Vertically?

s713221 at student.gu.edu.au s713221 at student.gu.edu.au
Thu Apr 19 05:39:30 EDT 2001


XiaoQin Xia wrote:
> 
> I am using Tk to draw 2-D charts. But I do not know how to write text
> vertically on canvas. Would you please show me how to do it?
> 
> Many Thanks from
> XiaoQin (xq.xia at ccsr.cam.ac.uk)

If you mean drawing rotated text, the underlying Tk doesn't support it
(one of the few things), so Tkinter won't either. If this is what you're
after, you may be more interested in wxPython's Device Contexts. I think
sping also has something as well. Both are at sourceforge.
However, if you're just trying to create text with one character per
line, e.g.
L
i
k
e

T
h
i
s

In Python 2.*
>>> import Tkinter
>>> import tkFont
>>> root = Tkinter.Tk()
>>> c = Tkinter.Canvas(root); c.pack(expand='yes', fill='both')
>>>
>>> myfont = tkFont.Font(root = c, family='times', size=12, weight=tkFont.NORMAL)
>>> metrics = myfont.metrics() #I've sometimes font repetitive calling of .metrics causes a core crash *shrugs*
>>> spacing = metrics['ascent'] + metrics['descent']
>>>
>>> y = 25 # Or wherever you want to start
>>> for i in "Like This":
	c.create_text(25, y, text = i, font = myfont)
	y += spacing

If you're trying to make labels for the y-axis, this will do, but I'd 
agree if you said it doesn't look as good as rotated text. 

On the other hand, there are several tools that already exist for
greating charts. PMW contains an interface to Blt's chart functions. You
may also want to look up The Vaults of Parnassus under the Graphics
section.
url: http://www.vex.net/parnassus/

Joal Heagney/AncientHart



More information about the Python-list mailing list