我正在尝试将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所知,我做的正确。怎么了?