• <tfoot id='dkcbu'></tfoot>

    <i id='dkcbu'><tr id='dkcbu'><dt id='dkcbu'><q id='dkcbu'><span id='dkcbu'><b id='dkcbu'><form id='dkcbu'><ins id='dkcbu'></ins><ul id='dkcbu'></ul><sub id='dkcbu'></sub></form><legend id='dkcbu'></legend><bdo id='dkcbu'><pre id='dkcbu'><center id='dkcbu'></center></pre></bdo></b><th id='dkcbu'></th></span></q></dt></tr></i><div id='dkcbu'><tfoot id='dkcbu'></tfoot><dl id='dkcbu'><fieldset id='dkcbu'></fieldset></dl></div>

        <bdo id='dkcbu'></bdo><ul id='dkcbu'></ul>
      1. <small id='dkcbu'></small><noframes id='dkcbu'>

        <legend id='dkcbu'><style id='dkcbu'><dir id='dkcbu'><q id='dkcbu'></q></dir></style></legend>
      2. kivy.uix.screenmanager.ScreenManagerException:ScreenManager 只

        时间:2023-10-09

        • <small id='LPaYT'></small><noframes id='LPaYT'>

        • <i id='LPaYT'><tr id='LPaYT'><dt id='LPaYT'><q id='LPaYT'><span id='LPaYT'><b id='LPaYT'><form id='LPaYT'><ins id='LPaYT'></ins><ul id='LPaYT'></ul><sub id='LPaYT'></sub></form><legend id='LPaYT'></legend><bdo id='LPaYT'><pre id='LPaYT'><center id='LPaYT'></center></pre></bdo></b><th id='LPaYT'></th></span></q></dt></tr></i><div id='LPaYT'><tfoot id='LPaYT'></tfoot><dl id='LPaYT'><fieldset id='LPaYT'></fieldset></dl></div>

            <legend id='LPaYT'><style id='LPaYT'><dir id='LPaYT'><q id='LPaYT'></q></dir></style></legend>
            • <bdo id='LPaYT'></bdo><ul id='LPaYT'></ul>

                  <tbody id='LPaYT'></tbody>

                <tfoot id='LPaYT'></tfoot>
                  本文介绍了kivy.uix.screenmanager.ScreenManagerException:ScreenManager 只接受 Screen 小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试创建启动画面.

                  I am trying to create a splash screen.

                  这里是代码.

                  from kivy.app import App
                  from kivy.uix.image import Image
                  from kivy.uix.screenmanager import ScreenManager, Screen
                  from kivy.animation import Animation
                  
                  
                  
                  
                  class ScreenOne(Screen):
                  
                          wing1 = Image(source="F:PyCharm Python WorksKivy Testopencityicon.png", pos=(0, 0), opacity=0)
                          anim1 = Animation(duration=4, opacity=1)
                          anim1.start(wing1)
                  
                  
                  class ScreenTwo(Screen):
                  
                          wing = Image(source="F:PyCharm Python WorksKivy Testopencityicon.png", pos=(0, 0), opacity=1)
                          animation = Animation(duration=2, opacity=0)
                          animation.start(wing)
                  
                  
                  sm = ScreenManager()
                  sm.add_widget(ScreenOne)
                  sm.add_widget(ScreenTwo)
                  sm.current = ScreenOne
                  
                  
                  class Arge(App):
                  
                      def build(self):
                          pass
                  
                  
                  
                  if __name__ == "__main__":
                      Arge().run()
                  

                  错误:

                  [INFO   ] [Logger      ] Record log in C:Userskanna.kivylogskivy_20-02-16_16.txt
                  [INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.2.0
                  [INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.2.0
                  [INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.1.23
                  [INFO   ] [Kivy        ] v1.11.1
                  [INFO   ] [Kivy        ] Installed at "F:Python Kivylibsite-packageskivy\__init__.py"
                  [INFO   ] [Python      ] v3.7.6 (tags/v3.7.6:43364a7ae0, Dec 18 2019, 23:46:00) [MSC v.1916 32 bit (Intel)]
                  [INFO   ] [Python      ] Interpreter at "F:Python KivyScriptspython.exe"
                  [INFO   ] [Factory     ] 184 symbols loaded
                  [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
                  [INFO   ] [Window      ] Provider: sdl2
                  [INFO   ] [GL          ] Using the "OpenGL" graphics system
                  [INFO   ] [GL          ] GLEW initialization succeeded
                  [INFO   ] [GL          ] Backend used <glew>
                  [INFO   ] [GL          ] OpenGL version <b'4.6.0 - Build 26.20.100.7262'>
                  [INFO   ] [GL          ] OpenGL vendor <b'Intel'>
                  [INFO   ] [GL          ] OpenGL renderer <b'Intel(R) UHD Graphics 630'>
                  [INFO   ] [GL          ] OpenGL parsed version: 4, 6
                  [INFO   ] [GL          ] Shading version <b'4.60 - Build 26.20.100.7262'>
                  [INFO   ] [GL          ] Texture max size <16384>
                  [INFO   ] [GL          ] Texture max units <32>
                  [INFO   ] [Window      ] auto add sdl2 input provider
                  [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
                  [INFO   ] [GL          ] NPOT texture support is available
                   Traceback (most recent call last):
                     File "F:/PyCharm Python Works/Kivy Test/splashscreen.py", line 25, in <module>
                       sm.add_widget(ScreenOne)
                     File "F:Python Kivylibsite-packageskivyuixscreenmanager.py", line 979, in add_widget
                       'ScreenManager accepts only Screen widget.')
                   kivy.uix.screenmanager.ScreenManagerException: ScreenManager accepts only Screen widget.
                  

                  这是错误日志.为什么会这样显示.我尝试编辑,但它根本不起作用.因此,鉴于代码在编辑时不起作用.提前致谢.我尝试只使用动画.但它也不起作用.

                  This is the error log. Why does it shows like this. I tried editing but it doesn't work at all. So given the code that it doesn't working when edited. Thanks in advance. I tried using the Animation only. but it doesn't work also.

                  推荐答案

                  你的代码有以下问题:

                  • ScreenManager 需要 Screen 类型的对象,不等待 Screen 类.
                  • 必须为每个屏幕设置一个名称,并且该名称必须传递给当前屏幕.
                  • 图片必须通过布局放置在屏幕内.
                  • 动画必须在屏幕显示时执行的on_enter方法中启动.
                  • App 的 build 方法必须返回一个 widget.
                  • 如果您想要连续播放 2 个动画,则必须使用+"运算符.

                  考虑到上面的解决方案是:

                  Considering the above the solution is:

                  import os
                  
                  from kivy.app import App
                  
                  from kivy.uix.image import Image
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.uix.screenmanager import ScreenManager, Screen
                  
                  from kivy.animation import Animation
                  
                  current_dir = os.path.dirname(os.path.realpath(__file__))
                  
                  
                  class ScreenOne(Screen):
                      def __init__(self, **kwargs):
                          super().__init__(**kwargs)
                          self.img = Image(source=os.path.join(current_dir, "opencityicon.png"))
                          box_layout = BoxLayout()
                          self.add_widget(box_layout)
                          box_layout.add_widget(self.img)
                  
                      def on_enter(self):
                          self.img.opacity = 0
                          animation = Animation(duration=4, opacity=1) + Animation(duration=4, opacity=0)
                          animation.start(self.img)
                  
                  
                  sm = ScreenManager()
                  sm.add_widget(ScreenOne(name="screen_one"))
                  sm.current = "screen_one"
                  
                  
                  class Arge(App):
                      def build(self):
                          return sm
                  
                  
                  if __name__ == "__main__":
                      Arge().run()
                  

                  这篇关于kivy.uix.screenmanager.ScreenManagerException:ScreenManager 只接受 Screen 小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:单击 Kivy Python 时返回按钮的 ID 下一篇:如何在 Kivy 中自定义 style.kv

                  相关文章

                  最新文章

                  <i id='uKcxT'><tr id='uKcxT'><dt id='uKcxT'><q id='uKcxT'><span id='uKcxT'><b id='uKcxT'><form id='uKcxT'><ins id='uKcxT'></ins><ul id='uKcxT'></ul><sub id='uKcxT'></sub></form><legend id='uKcxT'></legend><bdo id='uKcxT'><pre id='uKcxT'><center id='uKcxT'></center></pre></bdo></b><th id='uKcxT'></th></span></q></dt></tr></i><div id='uKcxT'><tfoot id='uKcxT'></tfoot><dl id='uKcxT'><fieldset id='uKcxT'></fieldset></dl></div>

                  <small id='uKcxT'></small><noframes id='uKcxT'>

                      <bdo id='uKcxT'></bdo><ul id='uKcxT'></ul>
                  1. <tfoot id='uKcxT'></tfoot>
                    1. <legend id='uKcxT'><style id='uKcxT'><dir id='uKcxT'><q id='uKcxT'></q></dir></style></legend>