Tk Canvas text question

G

Gary Richardson

I've been working on a Python version of Andreas Weber's ASCII
schematic drawing program ( http://www.tech-chat.de) ; not that I
thought I could do it better but just as a programming exercise.
I've managed to put together something that more or less works
but I'm puzzled by the way ASCII characters are displayed on a Canvas
window. For example, in the code below (which produces my crude
representation of an OpAmp), why are two leading blanks required in
the text of the second create_text statement to cause the vertical bar to
be aligned with the one above it? And why does the number of trailing
blanks affect the position of the beginning of a line. In the first two
statements trailing blanks are required because of the backslash.
But if a trailing blank is not included in the last create_text statement
the beginning of the displayed line is shifted to the right one character.
Additional trailing blanks shifts the line further to the left. The other
lines are similarly affected if additional trailing blanks are added to the
text.

I'm using ActivePython 2.2.2, build 224 on Win98SE.

Thanks,
Gary Richardson

from Tkinter import *
root = Tk()
canvas = Canvas(root, width=400, height=200, bg='white' )
canvas.pack()
font=('courier', 8)
canvas.create_text(40, 20, text='-|\ ', font=font)
canvas.create_text(40, 30, text=' | \ ', font=font)
canvas.create_text(40, 40, text=' | /', font=font)
canvas.create_text(40, 50, text='-|/ ', font=font)
root.mainloop()
 
F

Fredrik Lundh

Gary said:
I've been working on a Python version of Andreas Weber's ASCII
schematic drawing program ( http://www.tech-chat.de) ; not that I
thought I could do it better but just as a programming exercise.
I've managed to put together something that more or less works
but I'm puzzled by the way ASCII characters are displayed on a Canvas
window. For example, in the code below (which produces my crude
representation of an OpAmp), why are two leading blanks required in
the text of the second create_text statement to cause the vertical bar to
be aligned with the one above it? And why does the number of trailing
blanks affect the position of the beginning of a line.

by default, text is centered around the given coordinate. use anchor=NW
to align on the upper left corner, anchor=SW to align on the lower left, etc.

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top