[Tutor] Placement of text on a canvas

Rick Pasotto rick@niof.net
Fri Mar 28 22:01:02 2003


On Thu, Mar 06, 2003 at 02:33:13PM -0600, Henry Steigerwaldt wrote:
> To All:
> 
> I am puzzled how the placement of text occurs on a canvas widget of
> Tkinter.
> 
> For example, say the following line of numbers is plotted using a
> certain x,y value for text placement:
> 
>              30/40/80/90
> 
> Now say I add two more numbers to the line and use the same x,y value
> for text placement. What happens is that the beginning or left edge of
> the text shifts to the left as shown immediately below, rather than
> starting at the same x,y location and extending from there TO THE
> RIGHT:
> 
>     30/40/80/90/10/100
> 
> 
> I would think that as additional numbers are added to the line, the
> text would extend further to the right, NOT TO THE LEFT. This makes it
> impossible to keep the start of the text anchored at the same
> location.
> 
> The "justify" option will only matter if the text is displayed as
> multiple lines. I just have one line of text so that's out. Also the
> "anchor" option does not anchor the left side of the text when
> additional numbers are added to the line.
> 
> Below is the line of code I am using:
> 
> canvas.create_text(100,342, text='P    ' + '10/20/40/40', fill='red',
> font=('verdana', 8, 'bold'))
> 
> The "P" stands for the Probability of Precipitation, and the numbers
> are the probabilities for different periods of time. They can vary
> from single digits (2, 5 etc.) to 100, hence the varying line length,
> even when no additional numbers are added to the line.
> 
> What can I do to keep the left side (start of numbers) AT THE SAME X,Y
> LOCATION from changing? Is there an option that would work?

You need to add the option 'anchor=W'. Thus:

canvas.create_text(30,30,text="whatever",fill='red',anchor=W)

You are deleting the first text item aren't you?

-- 
"The secret wealth of commerce & the precarious profits of art & labor
are susceptible only of a discretionary value, which is seldom
disadvantageous to the interest of the treasury...  the payment of the
imposition, which in the case of a land tax may be obtained by seizure
of property, can rarely be extorted by any other means than those of
corporal punishments."
		-- Edward Gibbon 1788 _The Decline & Fall of the Roman
		   Empire_ (quoted in Charles Adams 1993 _For Good &
		   Evil: The Impact of Taxes on the Course of Civilization_)
    Rick Pasotto    rick@niof.net    http://www.niof.net