Window.size = (350, 600)
kv = '''
MDFloatLayout:
md_bg_color: 1, 1, 1, 1
MDLabel:
id: text1
text: "Hello"
halign: "center"
font_name: "BPoppins"
font_size: "40sp"
opacity: 1
MDLabel:
id: text2
text: "I'm Percy Black"
halign: "center"
font_name: "BPoppins"
font_size: "40sp"
opacity: 0
MDLabel:
id: text3
text: "Python Developer"
halign: "center"
font_name: "BPoppins"
font_size: "40sp"
opacity: 0
MDLabel:
id: text4
text: "."
halign: "center"
font_name: "BPoppins"
font_size: "40sp"
opacity: 0
'''
class ChangingText(MDApp):
def on_start(self):
self.start()
def start(self, *args):
# Animate the opacity of each label
for i in range(1, 5):
anim = Animation(opacity=0, duration=3)
anim.start(self.root.ids[f"text{i}"])
# Call the loop function
Animation.cancel_all(self.root)
Animation(opacity=1).start(self.root)
def loop(self, *args):
# Create a loop to animate the labels continuously
for i in range(1, 5):
anim = Animation(opacity=1, duration=3) + Animation(opacity=0, duration=3)
anim.start(self.root.ids[f"text{i}"])
# Schedule the loop function to run again
Animation.cancel_all(self.root)
Animation(opacity=0).start(self.root)
def build(self):
return Builder.load_string(kv)
if __name__ == "__main__":
ChangingText().run()
I want the text to fade in and fade out before the next text fades in. My output is either just one text appearing and no other texts later. Or all texts appearing concurrently.
I have tried to play with the opacity value to get these results but none of them are working.
I am sure it might be the loop function. But please have a look and let me know.