kivy: Проблема с выводом Layouts
Проблема в методе output() класса MainScreen. При попытке отобразить кнопку с помощью любого из Layouts, кнопки не выводятся. Я пытался вывести без использования Layouts и кнопки отобразились наложившись друг на друга(заменял 'return self.box.add_widget(self.but)' на 'return self.add_widget(self.but)'). Как осуществить вывод с помощью Layouts?
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.config import Config
from kivy.properties import ObjectProperty
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from os import listdir
Config.set("kivy", "keyboard_mode", "systemanddock")
class MainScreen(Screen):
def output(self):
"""Вывводит все заметки на главный экран."""
self.box = BoxLayout(orientation="vertical")
for self.file in listdir("Notes"):
print(self.file)
self.note = open("Notes\\" + self.file, "r")
self.all_str = self.note.readlines()
print(self.all_str[0])
self.but = Button(text=self.all_str[0],
size_hint=(0.9, 0.1))
return self.box.add_widget(self.but)
class AnotherScreen(Screen):
def create(self):
"""Создаёт новую задачу."""
header = ObjectProperty(None)
content = ObjectProperty(None)
file = open("Notes\\" + self.header.text + ".txt", "w")
file.write(self.header.text + "\n")
file.write(self.content.text)
file.close()
class WindowManager(ScreenManager):
pass
container = Builder.load_file("main.kv")
class Appilication(App):
def build(self):
return container
if __name__ == '__main__':
Appilication().run()
Файл main.kv:
WindowManager:
MainScreen:
AnotherScreen:
<MainScreen>:
name: "MainScreen"
Button:
text: "Вывести"
size_hint: 0.2, 0.2
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
on_release: root.output()
Button:
text: 'Добавить задачу'
font_size:"15sp"
size_hint: 0.2, 0.1
pos_hint: {'center_x': 0.86, 'center_y': 0.1}
on_release:
app.root.current = "note"
<AnotherScreen>:
name: "note"
Button:
text: 'Создать'
font_size:"15sp"
size_hint: 0.2, 0.1
pos_hint: {'center_x': 0.5, 'y': 0.1}
on_release:
app.root.current = "MainScreen"