Kivy教程乒乓球没有监听器错误。kv不能正确关闭

2024-10-03 11:25:20 发布

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

我不熟悉Python中的gui,想试试Kivy。 但在乒乓球教程中,我被卡住了: 我运行原始脚本并得到以下错误:

[WARNING           ] [Lang        ] The file C:\Users\Canopy\Skripts\Pong\pong.kv is loaded multiples times, you might have unwanted behaviors.
[INFO              ] [Base        ] Start application main loop
[ERROR             ] [Base        ] No event listeners have been created
[ERROR             ] [Base        ] Application will leave

为什么这些列表器丢失,为什么其他人(显然)可以运行代码?在

EDIT: A restart fixed it for once, but the next time I run the application I run into the same problem. The .kv doesn't seem to be properly closed.

我在win7上运行python2.7(canopy) 以下是脚本: 主.py公司名称:

^{pr2}$

以及乒乓球公司名称:

#:kivy 1.9.1

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

<PongPaddle>:
    size: 25, 200
    canvas:
        Rectangle:
            pos:self.pos
            size:self.size

<PongGame>:
    ball: pong_ball
    player1: player_left
    player2: player_right

    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: str(root.player1.score)

    Label:
        font_size: 70
        center_x: root.width * 3 / 4
        top: root.top - 50
        text: str(root.player2.score)

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

    PongPaddle:
        id: player_left
        x: root.x
        center_y: root.center_y

    PongPaddle:
        id: player_right
        x: root.width-self.width
        center_y: root.center_y

Tags: theposselfidbasesizetoproot