0

By default the canvas seems to go right and down, meaning that coordinate (0,0) is in the top left corner and coordinate (1,1) goes one right and one down. I was wondering if there is a way to change the orientation so that the origin is maybe bottom left and (1,1) would be one right and one up?

Tom
  • 2,545
  • 5
  • 31
  • 71

1 Answers1

3

The Canvas uses a 4 quadrant Cartesian coordinate (0,0 = top/left) When defining canvas = tk.Canvas(... try using scrollregion = "-200 -200 200 200" Try setting canvas.yview_scroll(0, "units") and canvas.xview_scroll(0, "units")

Here is a small demo.

import tkinter as tk

master = tk.Tk()

frame = tk.LabelFrame(master, text = "Coords Here", relief = tk.FLAT)
frame.grid(sticky = tk.NSEW)

canvas = tk.Canvas(
    frame, 
    highlightthickness = 0, background = "black",
    width = 400, height = 400, takefocus = 1,
    scrollregion = "-200 -200 200 200")
canvas.grid(sticky = tk.NSEW)

#canvas.yview_scroll(0, "units")
#canvas.xview_scroll(0, "units")

def rowcol(event):
    frame["text"] = f"{canvas.canvasx(event.x)} | {canvas.canvasy(event.y)}"

canvas.bind("<Motion>", rowcol)
master.mainloop()
Derek
  • 1,916
  • 2
  • 5
  • 15
  • Your answer does not address OP question. – acw1668 Jun 13 '22 at 15:57
  • My example puts 0,0 at the center of the canvas, it doesn't take much to effort to have 0,0 at bottom right of canvas, `scrollregion(-n, -n, 0, 0)` would do it. – Derek Jun 14 '22 at 00:29
  • But OP wants the coordinates go right and up, that is reverse y-axis. – acw1668 Jun 14 '22 at 02:21
  • Right and up puts 0,0 at bottom left, that's Quadrant 1, positive x and negative y `scrollregion = "0 -400 400 0")` in my example. – Derek Jun 14 '22 at 03:03