@iloveketchup

Как мне добавить текст через kivy?

Мне нужно добавить заголовок на первый экран.
Вот код, там в классе MainApp создал дополнительную функцию, у меня это один раз сработало, но я, видимо, делал что-то еще, при том остальные кнопки не отображались. В инете инфы вообзе не нашел, помогите разобраться, желательно с объянением)) Спасибо))
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label

Window.clearcolor = '#121212'
class MainApp(App):
    def text(self):
        title = Label(text='ABOBA',
                      bold=True,
                      pos_hint={'center_x': .5, 'center_y': .9},
                      background_color='#555555')
        return title

    def build(self):
        # Add the main and second screens to the manager, this class does nothing else
        sm.add_widget(MainScreen())
        sm.add_widget(SecondScreen())
        sm.add_widget(ThirdScreen())
        return sm  # Return the manager to work with him later

class MainScreen(Screen):
    def __init__(self):
        super().__init__()
        self.name = 'Main'  # setting the screen name value for the screen manager
        # (it's more convenient to call by name rather than by class)
        main_layout = FloatLayout()  # creating an empty layout that's not bound to the screen
        self.add_widget(main_layout)  # adding main_layout on screen

        # Button to get to the 2nd screen
        three_players = Button(text='3 игрока',
                            bold=True,
                            background_normal='',
                            background_color='#565656',
                            pos_hint={'center_x': .5, 'center_y': .35},
                            size_hint=(.7, .12),
                            color='#000000')
        three_players.bind(on_press=self.to_second_scrn)

        # Button to get to the 3rd screen
        four_players = Button(text='4 игрока',
                            bold=True,
                            background_normal='',
                            background_color='#565656',
                            pos_hint={'center_x': .5, 'center_y': .2},
                            size_hint=(.7, .12),
                            color='#000000')
        four_players.bind(on_press=self.to_third_scrn)

        main_layout.add_widget(three_players)
        main_layout.add_widget(four_players) # adding button on layout

    def to_second_scrn(self, *args):
        self.manager.current = 'Second'  # selecting the screen by name (in this case by name "Second")

    def to_third_scrn(self, *args):
        self.manager.current = 'Third'  # selecting the screen by name (in this case by name "Thrid")

    def build(self):
        title = Label(text="ABOBA",
                      pos_hint={'center_x': 1, 'center_y': .9},
                      )

        return title

class SecondScreen(Screen):
    def __init__(self):
        super().__init__()
    # on this screen, I do everything the same as on the main screen to be able to switch back and forth
        self.name = 'Second'
        second_layout = FloatLayout()
        self.add_widget(second_layout)

        Button
        Go_Back = Button(text='Go to Main screen',
                         size_hint=(.5, .5),
                         pos_hint={'center_x': .5, 'center_y': .5},
                         color='#ffff00')
        Go_Back.bind(on_press=self.to_main_scrn)

        second_layout.add_widget(Go_Back)

    def to_main_scrn(self, *args):  # together with the click of the button, it transmits info about itself.
        # In order not to pop up an error, add *args to the function
        self.manager.current = 'Main'
        return 0


class ThirdScreen(Screen):
    def __init__(self):
        super().__init__()
    # on this screen, do everything the same as on the main screen to be able to switch back and forth
        self.name = 'Third'
        third_layout = FloatLayout()
        self.add_widget(third_layout)

        # Button
        Go_Back = Button(text='Go to Main screen',
                         size_hint=(.5, .5),
                         pos_hint={'center_x': .5, 'center_y': .5},
                         color='#ffff00')

        Go_Back.bind(on_press=self.to_main_scrn)

        third_layout.add_widget(Go_Back)

    def to_main_scrn(self, *args):  # together with the click of the button, it transmits info about itself.
        # In order not to pop up an error, add *args to the function
        self.manager.current = 'Main'
        return 0


sm = ScreenManager()

if __name__ == '__main__':
    MainApp().run()
  • Вопрос задан
  • 51 просмотр
Пригласить эксперта
Ответы на вопрос 1
@PerchikII
Ф-ция создана, но её вызова я не вижу.
class MainScreen(Screen):
def __init__(self):
super().__init__()
self.name = 'Main' # setting the screen name value for the screen manager
# (it's more convenient to call by name rather than by class)
main_layout = FloatLayout() # creating an empty layout that's not bound to the screen
self.add_widget(main_layout) # adding main_layout on screen

title = Label(text='ABOBA',
bold=True,
pos_hint={'center_x': .5, 'center_y': .9})
# Button to get to the 2nd screen

three_players = Button(text='3 игрока',
bold=True,........
Я уё сюда впихнул.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы