Kivy 异常:未知类

发布于 2025-01-10 14:48:16 字数 2387 浏览 0 评论 0原文

运行我的代码似乎以异常错误结束,我已经尝试了很长时间来调试它,但我无法做到

main.py

from kivy.animation import Animation
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition
from gpshelper import GpsHelper
import plyer

class Manager(ScreenManager):
    pass



class SelectionScreen(Screen):
    def on_start(self):
        GpsHelper().run()


class Game(Screen):
    pass


class GpsBlinker():
    def blink(self):
        anim = Animation(opacity=0, blink_size=50)
        anim.bind(on_complete=self.reset)
        anim.start(self)

    def reset(self, *args):
        self.opacity = 1
        self.blink_size = self.default_blink_size
        self.blink()


kv = Builder.load_file("hiby.kv")

class HeIsBehindYou(App):
    def build(self):
        return kv

if __name__ == '__main__':
    HeIsBehindYou().run()

main.kv

#:import FadeTransition kivy.uix.screenmanager.FadeTransition

Manager:
    transition: FadeTransition()

    SelectionScreen:
        name:'selectionscreen'
    Game:
        name:'game'


<GpsBlinker>
    default_blink_size: 25
    blink_size: 25

    canvas.before:
        Color:
            rgba: 0.5, 0.5, 0.5, 1
        RoundedRectangle:
            radius:[root.blink_size/2.0, ]
            size: [root.blink_size, root.blink_size]
            pos: root.pos[0] + root.size[0]/2.0 - root.blink_size/2.0, root.pos[1] + root.size[1]/2.0 - root.blink_size/2.0



<SelectionScreen>
    BoxLayout:
        Image:
            source: 'placeholder.png'
            size: self.texture_size
        Button:
            text: 'Start Day 1'
            on_release:
                app.root.current = "game"
                root.manager.transition.direction = "up"
                print("inside")
                root.on_start()

<Game>
    id: game
    BoxLayout:
        orientation: 'vertical'
        Image:
            source: 'digital-grid-background.jpg'
            size: self.texture_size
            size_hint: 1, 3
        GpsBlinker:
            id: blinker

运行此代码后,我收到以下错误:

raise FactoryException('Unknown class <%s>' % name)
 kivy.factory.FactoryException: Unknown class <GpsBlinker

我尝试制作一个 GPS 模块来覆盖 game(screen) 中的动画。即使我在 main.py 文件中定义了它,我仍然收到此错误

Running my code seems to end in an Exception error, I have tried for a long time to debug this but I couldn't do it

main.py

from kivy.animation import Animation
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager, FadeTransition
from gpshelper import GpsHelper
import plyer

class Manager(ScreenManager):
    pass



class SelectionScreen(Screen):
    def on_start(self):
        GpsHelper().run()


class Game(Screen):
    pass


class GpsBlinker():
    def blink(self):
        anim = Animation(opacity=0, blink_size=50)
        anim.bind(on_complete=self.reset)
        anim.start(self)

    def reset(self, *args):
        self.opacity = 1
        self.blink_size = self.default_blink_size
        self.blink()


kv = Builder.load_file("hiby.kv")

class HeIsBehindYou(App):
    def build(self):
        return kv

if __name__ == '__main__':
    HeIsBehindYou().run()

main.kv

#:import FadeTransition kivy.uix.screenmanager.FadeTransition

Manager:
    transition: FadeTransition()

    SelectionScreen:
        name:'selectionscreen'
    Game:
        name:'game'


<GpsBlinker>
    default_blink_size: 25
    blink_size: 25

    canvas.before:
        Color:
            rgba: 0.5, 0.5, 0.5, 1
        RoundedRectangle:
            radius:[root.blink_size/2.0, ]
            size: [root.blink_size, root.blink_size]
            pos: root.pos[0] + root.size[0]/2.0 - root.blink_size/2.0, root.pos[1] + root.size[1]/2.0 - root.blink_size/2.0



<SelectionScreen>
    BoxLayout:
        Image:
            source: 'placeholder.png'
            size: self.texture_size
        Button:
            text: 'Start Day 1'
            on_release:
                app.root.current = "game"
                root.manager.transition.direction = "up"
                print("inside")
                root.on_start()

<Game>
    id: game
    BoxLayout:
        orientation: 'vertical'
        Image:
            source: 'digital-grid-background.jpg'
            size: self.texture_size
            size_hint: 1, 3
        GpsBlinker:
            id: blinker

After I run this I get the following error:

raise FactoryException('Unknown class <%s>' % name)
 kivy.factory.FactoryException: Unknown class <GpsBlinker

I tried to make a gps module to that overlays an animation in the game(screen). Even tho I have it defined in the main.py file, I still get this error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文