AttributeError:'模块'对象没有属性'textinput' [英] AttributeError: 'module' object has no attribute 'textinput'
问题描述
我使用Sublime Text,并且对该代码有疑问:
I use Sublime Text and have a problem with that code:
#coding: utf-8
import turtle
turtle.circle(20)
answer = turtle.textinput("Title", "Text")
运行它,我得到:
AttributeError: 'module' object has no attribute 'textinput'
我该如何解决?
推荐答案
您正在使用Python 2.
You are using Python 2.
运行
import sys
print(sys.version)
,它可能会输出类似
2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
这意味着您正在使用Python2.
which means that you are using Python 2.
roganjosh 指出,Python 2的turtle模块没有命令textinput
.如果要运行该代码,则需要使用python3.如果不确定如何切换版本,请在这篇文章中发表评论,说明如何安装Python以及如何运行程序,我将向您展示如何改用Python 3.
As roganjosh pointed out, Python 2's turtle module does not have the command textinput
. If you want to run that code, you need to use python 3. If you are unsure how to switch versions, leave a comment on this post saying how you installed Python, and how you run your programs, and I'll show you how to use Python 3 instead.
如果要继续使用Python 2,则必须运行该命令而不是该命令
If you want to continue with Python 2, then instead of that command you have to run
import tkSimpleDialog
answer = tkSimpleDialog.askstring("Text", "Text")
这完全相同.
这篇关于AttributeError:'模块'对象没有属性'textinput'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!