运行一个简单的pong教程时Kivy中的Typer错误

2024-06-11 15:39:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在学习在python中使用kivy。我按照这个教程创建一个简单的乒乓球游戏

https://kivy.org/docs/tutorials/pong.html

当我到达我试图给球做动画的地方。我写的代码和教程完全一样。我用F5从空闲状态运行程序,得到一个

return game()
Type Error: 'PongGame' object is not callable 

消息在交互式外壳和窗口的游戏本身冻结。有什么办法解决这个问题吗?提前谢谢

以下是我编写的代码(与教程完全相同):-

代码主.py在

^{pr2}$

代码庞千伏在

#:kivy 1.0.9

<PongBall>:
    size: 50, 50 
canvas:
    Ellipse:
        pos: self.pos
        size: self.size          

<PongGame>:
    ball: pong_ball

    canvas:
        Rectangle:
            pos: self.center_x-5, 0
            size: 10, self.height

    Label:
        font_size: 70  
        center_x: root.width / 4
        top: root.top - 50
        text: "0"

   Label:
       font_size: 70  
       center_x: root.width * 3 / 4
       top: root.top - 50
       text: "0"

   PongBall:
      id: pong_ball
      center: self.parent.center

Tags: 代码posself游戏sizetop教程root