0

Is it possible to use the turtle module to obtain coordinates (turtle.pos() once at the desired locations) without it opening a canvas?

I know this probably seems silly and defeats the point of the turtle module, but it's actually a very useful way of getting the coordinates of some points I need.

Many thanks

tomp
  • 55
  • 7
  • I think `turtle` is too intimately connected with `tkinter` to be capable of running without `tkinter` being initialized - which necessarily creates a window. You can hide that window by calling `.withdraw()` on it, or you can use `t = turtle.RawTurtle(tkinter.Canvas())` to create a turtle that is not connected with the window at all. – jasonharper Aug 17 '22 at 13:55
  • Might be an [xy problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/233676#233676). Can you provide more context of your original problem X? There might be a better solution than turtle. – ggorlen Aug 17 '22 at 14:55
  • I'm obtaining coordinates by: moving along circle segments (using the turtle circle method) then moving to an offset perpendicular to the turtle (turning the turtle 90 degrees). I have a series of circle segments for which the chord length and versine is known, and I am converting these to a radius and degree to use with the turtle circle method. I'm sure there is a better way! However, the turtle module works fine, I just don't need to see it. – tomp Aug 17 '22 at 15:34

1 Answers1

0

Instead of running turtle standalone, you could run it embedded and withdraw the root window on startup:

import tkinter as tk
from turtle import RawTurtle

root = tk.Tk()

root.withdraw()

canvas = tk.Canvas(width=500, height=500)

turtle = RawTurtle(canvas)

turtle.sety(-1)

turtle.circle(1, extent=45)

print(turtle.position())
cdlane
  • 40,441
  • 5
  • 32
  • 81