将TurtleScreen添加到画布:“顶级”对象没有属性“调用”

时间:2019-12-15 01:56:36

标签: python tkinter turtle-graphics tkinter-canvas

我正在尝试将TurtleScreen添加到tkinter Canvas中。下面的代码显示了我正在使用它的功能的开始,直到它中断为止:

def draw():
    top = Toplevel()
    top.title("Your Drawing!")
    canvas = Canvas(top)
    canvas.pack()
    ts = turtle.TurtleScreen(canvas)  # this is the line causing an exception (line 36 in traceback)

这是回溯:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Users/Blake/anaconda3/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "GUI.py", line 36, in draw
    ts = turtle.TurtleScreen(canvas)
  File "/Users/Blake/anaconda3/lib/python3.7/turtle.py", line 1001, in __init__
    rootwindow.call('wm', 'attributes', '.', '-topmost', '1')
AttributeError: 'Toplevel' object has no attribute 'call'

我不知道为什么要尝试调用Toplevel对象(我假设它正在尝试调用top对象)。据我从the docs所知,我做的正确。怎么了?

0 个答案:

没有答案