制作游戏时出错
有人知道这些错误意味着什么?
import turtle
sc = turtle.Screen()
sc.setup(width=1000, height=1000)
sc.title("pong")
sc.bgcolor("black")
sc.tracer(0)
def paddle_a():
paddle = turtle.Turtle()
paddle.penup()
paddle.color("white")
paddle.shape("square")
paddle.shapesize(stretch_wid=8.5, stretch_len=1)
paddle.goto(450, 0)
paddle.speed(0)
def paddle_b():
paddle = turtle.Turtle()
paddle.penup()
paddle.color("white")
paddle.shape("square")
paddle.shapesize(stretch_wid=8.5, stretch_len=1)
paddle.goto(-450, 0)
paddle.speed(0)
def ball_ball():
ball = turtle.Turtle()
ball.penup()
ball.color("white")
ball.shape("circle")
ball.shapesize(stretch_wid=1.5, stretch_len=1.5)
ball.goto(0, 0)
ball.speed(0)
ball.dx = 5
ball.dy =- 5
def paddleup():
y = paddle_a.ycore()
y =+ 20
paddle_a.sety(y)
sc.listen()
sc.onkeypress(paddleup, "w")
paddle_a()
paddle_b()
ball_ball()
while True:
sc.update()
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1885, in __call__
return self.func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 702, in eventfun
fun()
File "/Users//Python Projects/poooong.py", line 39, in paddleup
y = paddle_a.ycore()
AttributeError: 'function' object has no attribute 'ycore'
Traceback (most recent call last):
File "/Users//Python Projects/poooong.py", line 52, in <module>
sc.update()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 1304, in update
t._update_data()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 2647, in _update_data
self.screen._incrementudc()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 1293, in _incrementudc
raise Terminator
turtle.Terminator
香港专业教育学院试图在没有运气的情况下重新安装乌龟
anyone knows what these errors means?
import turtle
sc = turtle.Screen()
sc.setup(width=1000, height=1000)
sc.title("pong")
sc.bgcolor("black")
sc.tracer(0)
def paddle_a():
paddle = turtle.Turtle()
paddle.penup()
paddle.color("white")
paddle.shape("square")
paddle.shapesize(stretch_wid=8.5, stretch_len=1)
paddle.goto(450, 0)
paddle.speed(0)
def paddle_b():
paddle = turtle.Turtle()
paddle.penup()
paddle.color("white")
paddle.shape("square")
paddle.shapesize(stretch_wid=8.5, stretch_len=1)
paddle.goto(-450, 0)
paddle.speed(0)
def ball_ball():
ball = turtle.Turtle()
ball.penup()
ball.color("white")
ball.shape("circle")
ball.shapesize(stretch_wid=1.5, stretch_len=1.5)
ball.goto(0, 0)
ball.speed(0)
ball.dx = 5
ball.dy =- 5
def paddleup():
y = paddle_a.ycore()
y =+ 20
paddle_a.sety(y)
sc.listen()
sc.onkeypress(paddleup, "w")
paddle_a()
paddle_b()
ball_ball()
while True:
sc.update()
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1885, in __call__
return self.func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 702, in eventfun
fun()
File "/Users//Python Projects/poooong.py", line 39, in paddleup
y = paddle_a.ycore()
AttributeError: 'function' object has no attribute 'ycore'
Traceback (most recent call last):
File "/Users//Python Projects/poooong.py", line 52, in <module>
sc.update()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 1304, in update
t._update_data()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 2647, in _update_data
self.screen._incrementudc()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 1293, in _incrementudc
raise Terminator
turtle.Terminator
ive tryed to reinstall turtle with no luck
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码有很多问题。最明显的是,您要做的工作来创建两个桨和球,但切勿将它们分配给
paddle_a
,paddle_b
和ball
。除了ycore
@millertime指出的问题,另一个问题是您使用类似的操作员:哪些是错误或令人困惑的,应该是:
这是我的代码返还,解决这些问题和其他问题:
最后,您使用了<代码>虽然:不属于像乌龟这样的事件驱动环境。最终,您将需要使用屏幕
ontimer()
事件以保持球的发挥作用。There are a number of problems with your code. The most obvious is you do the work to create the two paddles and ball but never assign them to
paddle_a
,paddle_b
andball
. Besides theycore
issue noted by @MillerTime, another problem is you use operators like these:which are errors or confusing and should be:
Here's my rework of your code addressing these and other issues:
Finally, you use a
while True:
which doesn't belong in an event-driven environment like turtle. Eventually you'll instead want to use a screenontimer()
event to keep your ball in play.