-1
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label

from kivy.clock import Clock



class MyBox(BoxLayout):
    def __init__(self, my_text, **kwargs):
        super().__init__(orientation="vertical", padding=10, spacing=10, **kwargs)
        self.letters = []
        for i in my_text:
            self.letters.append(i)
        self.label = Label()
        self.add_widget(self.label)
        self.a=0
        self.label.text= ""
        while self.a < len(self.letters):
            try:
                Clock.schedule_once(self.change_text, 0.1)
                self.a=self.a+1
            except:
                break

    def change_text(self,dt):
        try:

            self.label.text = self.label.text + self.letters[self.a]
        except:
            print(self.a)




class MyApp(App):
    def build(self):
        box = MyBox("пример текста")
        return box


app = MyApp()
app.run()

1 ответ 1

0
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
    
from kivy.clock import Clock
    
class MyBox(BoxLayout):
        
    def __init__(self, **kwargs):
        super().__init__(orientation="vertical", padding=10, spacing=10, **kwargs)       
        self.label = Label()
        self.button = Button(text = 'Run')
        self.button.bind(on_release = self.run)
        self.text_input = TextInput()          
        self.add_widget(self.label)
        self.add_widget(self.text_input)
        self.add_widget(self.button)        
        
    def run(self, *args):
        self.label.text = ''
        self.start = Clock.schedule_interval(self.change_text, 0.2)
                            
    def change_text(self, instance, *args):
        my_text = self.text_input.text
        len_text = len(self.label.text)+1
        if len_text == len(my_text) or len(my_text) == 0:
            self.start.cancel()
            return
        self.label.text = f'{self.label.text}{my_text[len_text]}'
           
class MyApp(App):
    def build(self):
        box = MyBox()
        return box  
    
app = MyApp()
app.run()
1
  • Ваш ответ можно улучшить с помощью дополнительной информации. Пожалуйста, нажмите править для добавления подробностей, например, цитат или документации, чтобы другие могли подтвердить правильность вашего ответа. Вы можете найти дополнительную информацию о том, как писать хорошие ответы в Справке. 8 апр 2022 в 5:21

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.