<bdo id='TyMb9'></bdo><ul id='TyMb9'></ul>
  1. <i id='TyMb9'><tr id='TyMb9'><dt id='TyMb9'><q id='TyMb9'><span id='TyMb9'><b id='TyMb9'><form id='TyMb9'><ins id='TyMb9'></ins><ul id='TyMb9'></ul><sub id='TyMb9'></sub></form><legend id='TyMb9'></legend><bdo id='TyMb9'><pre id='TyMb9'><center id='TyMb9'></center></pre></bdo></b><th id='TyMb9'></th></span></q></dt></tr></i><div id='TyMb9'><tfoot id='TyMb9'></tfoot><dl id='TyMb9'><fieldset id='TyMb9'></fieldset></dl></div>
    <legend id='TyMb9'><style id='TyMb9'><dir id='TyMb9'><q id='TyMb9'></q></dir></style></legend>
  2. <small id='TyMb9'></small><noframes id='TyMb9'>

    1. <tfoot id='TyMb9'></tfoot>

      如何在 Kivy 中制作重复的旋转动画?

      时间:2023-10-09

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

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

            1. <tfoot id='cO5in'></tfoot>
                <tbody id='cO5in'></tbody>
              • <bdo id='cO5in'></bdo><ul id='cO5in'></ul>
                本文介绍了如何在 Kivy 中制作重复的旋转动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我想制作一个可以旋转加载微调器图像的动画小部件.我查看了 Animation 类,它似乎可以完成这项工作.但是我找不到一种方法来不断地在一个方向上旋转小部件

                I want to make an animated widget that would rotate the loading spinner image. I've looked into the Animation class and it seems like it can do the job. But I couldn't find a way to keep rotating the widget in a single direction constantly

                这是我的代码:

                from kivy.app import App
                from kivy.lang import Builder
                from kivy.uix.image import Image
                from kivy.graphics import Rotate
                from kivy.animation import Animation
                from kivy.properties import NumericProperty
                
                Builder.load_string('''                                                                                                                                        
                <Loading>:                                                                                                                                                 
                    canvas.before:                                                                                                                                             
                        PushMatrix                                                                                                                                             
                        Rotate:                                                                                                                                                
                            angle: self.angle                                                                                                                                  
                            axis: (0, 0, 1)                                                                                                                                    
                            origin: self.center                                                                                                                                
                    canvas.after:                                                                                                                                              
                        PopMatrix                                                                                                                                              
                ''')
                
                class Loading(Image):
                    angle = NumericProperty(0)
                    def __init__(self, **kwargs):
                        super().__init__(**kwargs)
                        anim = Animation(angle = 360)
                        anim += Animation(angle = -360)
                        anim.repeat = True
                        anim.start(self)
                
                
                class TestApp(App):
                    def build(self):
                        return Loading()
                
                TestApp().run()
                

                当您启动它时,您会看到该小部件在一个方向上旋转 360 度,然后旋转旋转.如何构建动画序列,使角度不断增加或每 360 次旋转下降到 0?

                When you launch it, you'll see that the widget rotates 360 degrees in one direction and then turns the rotation around. How could I build the animation sequence so that the angle would constantly keep increasing or would be dropped to 0 every 360-rotation?

                推荐答案

                您可以在 on_angle 方法中将角度设置为 0.这是一个稍作修改的版本:

                You can set your angle to 0 inside on_angle method. Here's a slightly modified version:

                from kivy.app import App
                from kivy.lang import Builder
                from kivy.uix.floatlayout import FloatLayout
                from kivy.animation import Animation
                from kivy.properties import NumericProperty
                
                Builder.load_string('''                               
                <Loading>:
                    canvas.before:
                        PushMatrix
                        Rotate:
                            angle: root.angle
                            axis: 0, 0, 1
                            origin: root.center
                    canvas.after:
                        PopMatrix
                
                
                    Image:
                        size_hint: None, None
                        size: 100, 100
                        pos_hint: {'center_x': 0.5, 'center_y': 0.5}
                ''')
                
                class Loading(FloatLayout):
                    angle = NumericProperty(0)
                    def __init__(self, **kwargs):
                        super(Loading, self).__init__(**kwargs)
                        anim = Animation(angle = 360, duration=2) 
                        anim += Animation(angle = 360, duration=2)
                        anim.repeat = True
                        anim.start(self)
                
                    def on_angle(self, item, angle):
                        if angle == 360:
                            item.angle = 0
                
                
                class TestApp(App):
                    def build(self):
                        return Loading()
                
                TestApp().run()
                

                这篇关于如何在 Kivy 中制作重复的旋转动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:我如何使用 Kivy (Python) 相机 下一篇:在使用 PyInstaller --onefile 打包 kivy 时包含 .kv/.js

                相关文章

                最新文章

              • <legend id='0fSQx'><style id='0fSQx'><dir id='0fSQx'><q id='0fSQx'></q></dir></style></legend>

                  <tfoot id='0fSQx'></tfoot>
                      <bdo id='0fSQx'></bdo><ul id='0fSQx'></ul>
                    <i id='0fSQx'><tr id='0fSQx'><dt id='0fSQx'><q id='0fSQx'><span id='0fSQx'><b id='0fSQx'><form id='0fSQx'><ins id='0fSQx'></ins><ul id='0fSQx'></ul><sub id='0fSQx'></sub></form><legend id='0fSQx'></legend><bdo id='0fSQx'><pre id='0fSQx'><center id='0fSQx'></center></pre></bdo></b><th id='0fSQx'></th></span></q></dt></tr></i><div id='0fSQx'><tfoot id='0fSQx'></tfoot><dl id='0fSQx'><fieldset id='0fSQx'></fieldset></dl></div>
                  1. <small id='0fSQx'></small><noframes id='0fSQx'>