Tk Canvas text question

Gary Richardson garyr at fidalgo.net
Mon Aug 25 23:23:40 EDT 2003


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()








More information about the Python-list mailing list