By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Tk Canvas text question

P: n/a
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()


Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gary Richardson wrote:
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>


Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.