问题
Python turtle works with tkinter. How to get the root
you know from tkinter?
Like this:
import tkinter
root = tkinter.Tk()
but for turtle.
回答1:
The top-level widget is available through the winfo_toplevel
method of the turtle canvas:
import turtle
canvas = turtle.getcanvas()
root = canvas.winfo_toplevel()
It is of a subtype of Tk
:
import tkinter
assert type(root) is turtle._Root
assert isinstance(root, tkinter.Tk)
回答2:
turtle.getcanvas()
returns the object you are (I am) looking for.
来源:https://stackoverflow.com/questions/34004152/python-turtle-get-tkinter-root