Некоторые проблемы с вашим кодом:
- Метод
build()
(или любой другой метод) может выполнять только один return
, поэтому ваш второй return
игнорируется. - У вас слишком много аргументов для вашего
circle
. origin
вашего Rotate
, вероятно, за пределами экрана. Я думаю, вы хотите повернуть вокруг центра круга. super()
в Loading2
ссылках Loading
вместо Loading2
. - Есть пара ошибок отступа (вероятно, просто из копирования / вставки кода).
Итак, вот модифицированная версия вашего кода, которая делает большую часть того, что вы хотите:
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
kv = '''
FloatLayout:
Loading:
size_hint: 0.3, 1
Loading2:
size_hint: 0.7, 1
pos_hint: {'right':1}
<Loading>:
canvas.before:
PushMatrix
Rotate:
angle: root.angle
axis: 0, 0, 1
origin: root.center
canvas.after:
PopMatrix
canvas:
Color:
rgba: .1, 1, .1, .9
Line:
width: 2.
circle:
(root.center_x, root.center_y, 100, 90, 180, 10)
<Loading2>:
canvas.before:
PushMatrix
Rotate:
angle: root.angle
axis: 0, 0, 1
origin: root.center
canvas.after:
PopMatrix
canvas:
Color:
rgba: .1, 1, .1, .9
Line:
width: 2.
circle:
(root.center_x, root.center_y, 200, 90, 180, 10)
'''
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 Loading2(FloatLayout):
angle = NumericProperty(0)
def __init__(self, **kwargs):
super(Loading2, 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 Builder.load_string(kv)
TestApp().run()
Я добавил root FloatLayout
в ваш kv
, так что оба класса Loading
и Loading2
находятся в вашем GUI.