我对 PyCharm 有疑问。我开始用 PyCharm 学习 python,我想用 turtle 包写一些。当我尝试执行此代码时
import turtle
bob = turtle.Turtle()
我有那个消息:
"C:\Program Files\Python36\python.exe" C:/Users/Ptr/Desktop/python/Proj_1/Gui.py
Traceback (most recent call last):
File "C:/Users/Ptr/Desktop/python/Proj_1/Gui.py", line 1, in <module>
import turtle
File "C:\Program Files\Python36\lib\turtle.py", line 107, in <module>
import tkinter as TK
File "C:\Users\Ptr\Desktop\python\tkinter.py", line 3, in <module>
okno = tkinter.Tk()
AttributeError: module 'tkinter' has no attribute 'Tk'
Process finished with exit code 1
当我尝试使用 IDLE 执行该代码时,一切正常。 在 PyCharm 中,我尝试在项目中安装 turtle:
Python>项目解释器
但我一直有同样的错误:
Collecting turtle
Using cached turtle-0.0.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Ptr\AppData\Local\Temp\pycharm-packaging\turtle\setup.py", line 40
except ValueError, ve:
except ValueError, ve:
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Ptr\AppData\Local\Temp\pycharm-packaging\turtle\
enter code here
后来遇到这个问题的人需要注意的几件事:
你不点龟。 Turtle 是一个内置的 python 包。 你只要说
import turtle
.