Kivy 异常:未知类
运行我的代码似乎以异常错误结束,我已经尝试了很长时间来调试它,但我无法做到
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论