AttributeError: '_Screen' object has no attribute 'onkeypress' python 的例子
来源:互联网 发布:清真食品 知乎 编辑:程序博客网 时间:2024/06/06 07:40
File "catGame.py", line 50, in <module>
window.onkeypress(up, "Up")
AttributeError: '_Screen' object has no attribute 'onkeypress'
import turtle
import time
boxsize = 200
caught = False
score = 0
#functions that are called on keypresses
def up():
mouse.forward(10)
checkbound()
def left():
mouse.left(45)
def left():
mouse.right(45)
def back():
mouse.backward(10)
checkbound()
def quitTurtlers():
window.bye()
#stop the mouse from leaving the square set by box size
def checkbound():
global boxsize
if mouse.xcor() > boxsize:
mouse.goto(boxsize, mouse.ycor())
if mouse.xcor() > boxsize:
mouse.goto(boxsize, mouse.ycor())
if mouse.xcor() > boxsize:
mouse.goto(boxsize, mouse.ycor())
if mouse.xcor() > boxsize:
mouse.goto(boxsize, mouse.ycor())
#set up screen
window = turtle.Screen()
mouse = turtle.Turtle()
cat = turtle.Turtle()
mouse.penup()
mouse.penup()
mouse.goto(100, 100)
#add key listeners
window.onkeypress(up, "Up")
window.onkeypress(Left, "Left")
window.onkeypress(Right, "Right")
window.onkeypress(back, "Down")
window.onkeypress(quitTurtles, "Escape")
diffculty = window.numimput("Diffculty",
"Enter a diffculty from easy (1), for hard (5)",
minval =1, maxval = 5)
window.listen()
#main loop
#note how it changes with diffculty
while not caught:
cat.setheading(cat.towards(mouse))
cat.forwards(8 + diffculty)
score = wcore + 1
if cat.diatance(mouse) < 5:
caught = True
time.sleep(0.2-(0.01*diffculty))
window.textinput("Game Over", "Well done. You scored:" + str(score*diffculty))
window.bye()
window.onkeypress(up, "Up")
AttributeError: '_Screen' object has no attribute 'onkeypress'
import turtle
import time
boxsize = 200
caught = False
score = 0
#functions that are called on keypresses
def up():
mouse.forward(10)
checkbound()
def left():
mouse.left(45)
def left():
mouse.right(45)
def back():
mouse.backward(10)
checkbound()
def quitTurtlers():
window.bye()
#stop the mouse from leaving the square set by box size
def checkbound():
global boxsize
if mouse.xcor() > boxsize:
mouse.goto(boxsize, mouse.ycor())
if mouse.xcor() > boxsize:
mouse.goto(boxsize, mouse.ycor())
if mouse.xcor() > boxsize:
mouse.goto(boxsize, mouse.ycor())
if mouse.xcor() > boxsize:
mouse.goto(boxsize, mouse.ycor())
#set up screen
window = turtle.Screen()
mouse = turtle.Turtle()
cat = turtle.Turtle()
mouse.penup()
mouse.penup()
mouse.goto(100, 100)
#add key listeners
window.onkeypress(up, "Up")
window.onkeypress(Left, "Left")
window.onkeypress(Right, "Right")
window.onkeypress(back, "Down")
window.onkeypress(quitTurtles, "Escape")
diffculty = window.numimput("Diffculty",
"Enter a diffculty from easy (1), for hard (5)",
minval =1, maxval = 5)
window.listen()
#main loop
#note how it changes with diffculty
while not caught:
cat.setheading(cat.towards(mouse))
cat.forwards(8 + diffculty)
score = wcore + 1
if cat.diatance(mouse) < 5:
caught = True
time.sleep(0.2-(0.01*diffculty))
window.textinput("Game Over", "Well done. You scored:" + str(score*diffculty))
window.bye()
这个程序哪里有错,纠结半天
阅读全文
0 0
- AttributeError: '_Screen' object has no attribute 'onkeypress' python 的例子
- python __def__ Exception AttributeError: "'NoneType' object has no attribute
- python __def__ Exception AttributeError: "'NoneType' object has no attribute
- [Python][转]Exception AttributeError: "'NoneType' object has no attribute
- Python:AttributeError: 'function' object has no attribute '_doc_'
- [Python]attributeError:'module' object has no attribute 'dump'
- [python错误]builtins.AttributeError: 'module' object has no attribute 'request'
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- python AttributeError: 'module' object has no attribute 'setdefaultencoding'
- [python]Django AttributeError 'tuple' object has no attribute 'regex'
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- python AttributeError: 'module' object has no attribute 'dumps'解决办法
- Python AttributeError: 'module' object has no attribute xxxx
- Python 【精】AttributeError: 'Module' object has no attribute 'STARTF_USESHOWINDOW'
- Python AttributeError: ‘module’ object has no attribute ‘A’
- AttributeError: 'module' object has no attribute 'face' 问题解决 opencv+python
- python 错误解析 AttributeError: 'module' object has no attribute 'dumps'
- 【python】AttributeError: 'module' object has no attribute 'HTTPSConnection'
- UE4 道路编辑 Spline的使用
- 导致微信公众平台设置网页授权域名“无法访问xxx指向的web服务器(或虚拟主机)的目录,请检查网络设置”的一种原因
- 项目日记3—服务器环境搭建(二)
- 蓝桥杯 算法训练 6-1 递归求二项式系数值
- Python(2)————变量的6大标准数据类型
- AttributeError: '_Screen' object has no attribute 'onkeypress' python 的例子
- Redis客户端之jedis的使用简介
- 用 Python 连接 MySQL 的几种姿势
- Class vs. Component vs. Control 类、组件和控件
- [luogu]P2085最小函数值-堆排的玄学运用
- 自定义参数绑定ConversionService和mvc:resources的命名冲突
- Tkinter教程之Listbox篇
- c++ 链表的初学
- java心得(hashmap之红黑树)