Tk Canvas text question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Richardson

    Tk Canvas text question

    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_t ext(40, 20, text='-|\ ', font=font)
    canvas.create_t ext(40, 30, text=' | \ ', font=font)
    canvas.create_t ext(40, 40, text=' | /', font=font)
    canvas.create_t ext(40, 50, text='-|/ ', font=font)
    root.mainloop()




  • Fredrik Lundh

    #2
    Re: Tk Canvas text question

    Gary Richardson wrote:
    [color=blue]
    > 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.[/color]

    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>




    Comment

    Working...