473,382 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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_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
1 7631
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mickel Grönroos | last post by:
Hi, I'm trying to put an Tkinter.Entry of fixed size onto a specific location on a canvas using the place manager. The idea is that one can double-click a rectangle object on a canvas to get an...
4
by: Peter Otten | last post by:
Is there a way to limit both width and height of a canvas text item? My current workaround seems clumsy: import Tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, width=400, height=200,...
3
by: Gigs_ | last post by:
how to write text on canvas. i know that i need to use canvas.create_text, but how to write text than when i create_text? or how to access object ID in canvas and change some options? thanks...
26
by: Jon Davis | last post by:
OK, why is Canvas not IDisposable, and how do I get rid of all the Windows handles? I'm doing a performance test of looping through a dynamic XAML-to-JPEG conversion. It gets to about 500...
6
by: Nebulism | last post by:
I have been attempting to utilize a draw command script that loads a canvas, and through certain mouse events, draws rectangles. The original code is from...
1
by: DemonFox | last post by:
Hello to all I need to merge my code with the PaintBox component. the question is: i have a form with edit box where you put the number (data) of the node you want to insert ant it comes to the...
2
by: devnew | last post by:
hi i am new to tkinter and would like some help with canvas i am doing validation of contents of a folder and need to show the ok/error messages on a canvas resultdisplay =Canvas(...)...
10
by: blaine | last post by:
Hey everyone! I'm not very good with Tk, and I am using a very simple canvas to draw some pictures (this relates to that nokia screen emulator I had a post about a few days ago). Anyway, all is...
4
by: moondaddy | last post by:
I have a wpf project where I use a canvas to drag shapes around. when I drag a shape beyond the right or bottom side I get scrollbars which is good. I also get scrollbars when I zoom in and a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.