Tk Canvas text question
garyr at fidalgo.net
Tue Aug 26 05:23:40 CEST 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
I'm using ActivePython 2.2.2, build 224 on Win98SE.
from Tkinter import *
root = Tk()
canvas = Canvas(root, width=400, height=200, bg='white' )
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)
More information about the Python-list