@keynet

Белый экран вместо моего приложения на kivy, как исправить?

Я решил сделать приложение, и хотел сделать окно с пасхалками, но теперь экран белый, до того как я решил сделать переключение между окнами выглядело вот так 64e1f0b171a87530408489.png
теперь это просто белый экран, вот весь код(он очень большой)

from kivy.uix.button import Button
from kivy.uix.label import Label
from kivymd.app import MDApp
from kivy.uix.textinput import TextInput
import csv
import codecs
from kivy.uix.image import Image
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window
from kivy.core.text import LabelBase
from kivy.animation import Animation
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.lang import Builder


Window.icon = 'data/icon.png'
percentage = None
first_name = None
second_name = None
# Set the screen size
Window.size = (540, 960)
class ScreenManagement(ScreenManager):
    def __init__(self, **kwargs):
        super(ScreenManagement, self).__init__(**kwargs)
        self.add_widget(NameApp(name='name_app'))
        self.add_widget(EasterEggScreen(name='easter_egg'))

class EasterEggScreen(Screen):
    def __init__(self, **kwargs):
        super(EasterEggScreen, self).__init__(**kwargs)
        LabelBase.register(name='WhiteFont', fn_regular='data/406-font.otf')
        self.back_button = Button(text='Назад', font_size='36sp', height='72dp', color='black',
                                  size_hint=(0.4, 0.1), pos_hint={'center_x': 0.0, 'center_y': 0.1},
                                  font_name='WhiteFont')
        self.add_widget(self.back_button)
        self.back_button.bind(on_press=self.go_back)

    def go_back(self, instance):
        self.manager.current = 'name_app'  # Переключаемся на главный экран (с именами)

class NameApp(Screen):
    def __init__(self, **kwargs):
        super(NameApp, self).__init__(**kwargs)
        def calculate_percentage(first_name, second_name):
            global percentage

            with codecs.open('data/russian_male_names.csv', 'r', encoding='utf-8') as file:
                reader = csv.reader(file)
                for row in reader:
                    name = row[0]
                    count = int(row[1])

                    if first_name.lower() == name.lower():
                        with codecs.open('data/russian_female_names.csv', 'r', encoding='utf-8') as file1:
                            reader1 = csv.reader(file1)
                            for row1 in reader1:
                                name_fem = row1[0]
                                count_fem = int(row1[1])
                                if second_name.lower() == name_fem.lower():
                                    result = count // count_fem
                                    if result <= 0:
                                        result = 1
                                    percentage = result * 2

                                    if percentage > 20:
                                        percentage = 20

                                  
                                    first_name = None
                                    second_name = None
                                    percentage = None

        def build():
            layout = FloatLayout()

            LabelBase.register(name='WhiteFont', fn_regular='data/406-font.otf')
            background = Image(source='data/Wallpaper.png', allow_stretch=True)
            layout.add_widget(background)

            my_lab = Label(text='Напиши имя', markup=True, font_size='36sp', color='black', size_hint=(0.8, 0.1),
                           pos_hint={'top': 1, 'center_x': 0.50}, bold=True, font_name='WhiteFont')
            layout.add_widget(my_lab)

            my_name_layout = FloatLayout(size_hint=(0.5, 0.2), pos_hint={'center_x': 0.5, 'center_y': 0.75})
            my_name_label = Label(text='Первое Имя:', font_size='24sp', color='black', size_hint=(0.55, 1),
                                  pos_hint={'left_x': 0, 'center_y': 0.5}, bold=True, font_name='WhiteFont')
            self.first_name_input = TextInput(multiline=False, hint_text="Введите мужское имя", font_size='24sp',
                                              font_name='WhiteFont',
                                              size_hint=(1.2, 0.6), pos_hint={'right': 1.4, 'center_y': 0.5})
            my_name_layout.add_widget(my_name_label)
            my_name_layout.add_widget(self.first_name_input)
            layout.add_widget(my_name_layout)

            op_name_layout = FloatLayout(size_hint=(0.5, 0.2), pos_hint={'center_x': 0.5, 'center_y': 0.55})
            op_name_label = Label(text='Второе Имя:', font_size='24sp', color='black', size_hint=(0.55, 1),
                                  pos_hint={'left_x': 0, 'center_y': 0.5}, bold=True, font_name='WhiteFont')
            self.second_name_input = TextInput(multiline=False, hint_text="Введите женское имя", font_size='24sp',
                                               size_hint=(1.2, 0.6), pos_hint={'right': 1.4, 'center_y': 0.5},
                                               font_name='WhiteFont')
            op_name_layout.add_widget(op_name_label)
            op_name_layout.add_widget(self.second_name_input)
            layout.add_widget(op_name_layout)

            self.result_label = Label(text='Результат:', font_size='36sp', size_hint=(0.8, 0.1),
                                      font_name='WhiteFont', color='black', opacity=0)
            self.result_label.pos_hint = {'center_x': 0.5, 'center_y': 0.25}
            layout.add_widget(self.result_label)

            self.my_but = Button(text='Результат', font_size='36sp', height='72dp', color='black', size_hint=(0.4, 0.1),
                                 pos_hint={'center_x': 0.5, 'center_y': 0.1}, font_name='WhiteFont')
            self.my_but.bind(on_press=self.on_button_click)
            layout.add_widget(self.my_but)

            return layout


        def on_button_click(self, instance):
            global percentage
            self.my_but.pos_hint = {'center_x': 0.5, 'center_y': -1}
            self.my_but.opacity = 0
            self.result_label.color[3] = 1
            first_name = self.first_name_input.text
            second_name = self.second_name_input.text
            self.calculate_percentage(first_name, second_name)

            def update_result_label_text(*args):
                global percentage
                if percentage is not None:
                    percentage = percentage + 10
                    percentage = percentage * 2
                    if percentage > 100:
                        percentage = percentage // 2
                        if percentage > 100:
                            percentage = 100
                    self.result_label.text = f'Результат: {percentage}%'
                    percentage = None
                else:
                    self.result_label.text = 'Имя(имена) не найдены'
                Clock.schedule_once(fade_out, 5)
            def fade_out(*args):
                animation1 = Animation(opacity=0, duration=1)
                animation1.start(self.result_label)
                animation2 = Animation(pos_hint={'center_x': 0.5, 'center_y': 0.1}, opacity=1, duration=1)
                animation2.start(self.my_but)

            animation = Animation(opacity=1, duration=1)
            animation.bind(
                on_complete=update_result_label_text)  # Привязываем обновление текста к завершению анимации
            animation.start(self.result_label)



class Application(MDApp):
    def build(self):
        sm = ScreenManagement(transition=FadeTransition())
        sm.add_widget(EasterEggScreen(name='easter_egg'))
        sm.add_widget(NameApp(name='name_app'))
        sm.current = 'name_app'

        return sm


if __name__ == '__main__':
    Application().run()
  • Вопрос задан
  • 90 просмотров
Пригласить эксперта
Ответы на вопрос 1
@keynet Автор вопроса
Я забыл написать в конце nameapp self.add_widget(layout)
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Похожие вопросы