Python turtle get tkinter root

匆匆过客 提交于 2020-01-14 05:33:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!