首页 > 解决方案 > 新版python中代码发生了变化

问题描述

我需要一些帮助,因为我现在正在编写一个乒乓球游戏,但是帮助我使用 python 版本的视频是 3.6,我正在用 python 3.8 编写它,我遇到了一个问题,我得到的错误是 "turtle has no attribute dx",有人知道我要写什么新版本的python吗?

while True:
    wn.update()
    
    ball.setx(ball.xcor() + ball.dx)
    ball.sety(ball.ycor() + ball.dy)

这就是让球移动的代码。

标签: python

解决方案


我从你说的地方得到了代码, http://christianthompson.com/sites/default/files/Pong/pong.py

在这里,在这部分代码中

# Ball
ball = turtle.Turtle()
ball.speed(0)
ball.shape("square")
ball.color("white")
ball.penup()
ball.goto(0, 0)
ball.dx = 2
ball.dy = 2

他定义了 dx 和 dy 的值。这不是版本的错误。


推荐阅读