tags:

views:

37

answers:

2

I have the following code:

from Tkinter import *

master = Tk()
canvas = Canvas(master, width=640, height=480, bd=0)
canvas.pack()

line_coords = (3, 3, 3, 100)
canvas.create_line(*line_coords, fill='red')

mainloop()

This will draw a line in the top-left corner. Why is it that if I change line_coords to (2, 2, 2, 100) the line does not render? It's as if the coordinate system starts at (3, 3).

A: 

the coordinate system may start at the top left corner including the operating system's title bar and border, so you have to render to the right and down a bit.

It's usually an operating system dependent thing.

alphomega
Is there a way I can get tkinter to automatically translate the coordinates as necessary? Or could I at least determine what the offset is programmatically to make the translations myself?
ysimonson
Not sure about this, since it is operating-system specific but if you know you're only going to use the program on one operating system, you could always make your own function.
alphomega
@alphomega: this answer is completely false.
Bryan Oakley
+1  A: 

Canvas coordinates unequivocally start at zero, and the window frame has nothing to do with your problem.

The problem is that the default highlightthickness for a canvas on your system is 3, and that is what is obscuring your line. Try setting the highlightthickness to zero and you'll see your line even if the x coordinate is 0.

Unfortunately, both the borderwidth and highlightthickness encroach on the coordinate system of the canvas.

Bryan Oakley
Yes, you're right. Setting highlightthickness to 0 fixed the problem. Thanks!
ysimonson