How to I get the positions for the corners of a turtle screen embeded in a tkinter canvas

4 weeks ago 39
ARTICLE AD BOX

I'm trying to draw a grid in the turtle, but doing so requires knowing the positions of the corners of the screen.

turtle.goto(0, 0) does not move the turtle to the middle of the screen; instead, it goes within the top left quadrant of the screen.

from tkinter import * from turtle import RawTurtle, TurtleScreen root = Tk() root.attributes('-fullscreen', True) for i in range(10): root.rowconfigure(i, weight =1, uniform = True) for i in range(16): root.columnconfigure(i, weight=1, uniform = True) Canvas = Canvas(root, bg = 'white') Canvas.grid(row = 2, column = 9, rowspan = 6, columnspan = 6, sticky = 'nesw' Screen = TurtleScreen(Canvas) topleft_x = (int(Canvas['width']) / -2) topleft_y = (int(Canvas['height']) / 2)

this gives the x and y coordinates for the top-left corner of the screen, But because (0, 0) is not in the center of the screen, just using the negatives of those values doesn't actually give coordinates for the other corners.

Also Canvas.winfo_reqwidth() + (int(Canvas['width']) gives the correct x-position for the right edge, but -(Canvas.winfo_reqheight() - (int(Canvas['height'])))doesn't give the correct y-position for the bottom edge.

Read Entire Article