python Kivy错误- 'NoneType'对象没有属性'transition'帮助我

zsohkypk  于 2023-04-10  发布在  Python
关注(0)|答案(1)|浏览(90)
import kivy

kivy.require('2.1.0') # replace with your current kivy version !

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.screenmanager import SlideTransition

fontName = 'NanumGaRamYeonGgoc.ttf'

class InputScreen(GridLayout, Screen):
    def __init__(self, **kwargs):
        super(InputScreen, self).__init__(**kwargs)
        self.cols = 2
        self.add_widget(Label(text='로그라인: ', font_name=fontName, font_size=40))
        self.logline = TextInput(multiline=False)
        self.add_widget(self.logliine)
        self.add_widget(Label(text='주제: ', font_name=fontName, font_size=40))
        self.plot = TextInput(multiline=False)
        self.add_widget(self.plot)

        layout = BoxLayout(orientation = 'vertical')
                

        naving = BoxLayout(size_hint_y=0.2)

        created = Button(text='이야기 만들기', font_name=fontName, font_size=30)
                

        created.bind(on_release=self.switch_created)
                

        naving.add_widget(created)
        layout.add_widget(naving)

        self.add_widget(layout)

    def switch_created(self, *args):
        self.manager.transition = SlideTransition(direction="right")
        self.manager.current = self.manager.previous()

class MyApp(App):
    def build(self):
        return InputScreen()

if __name__ == '__main__':
    MyApp().run()

我试图创建的是得到'logline'和'plot'输入,并按下按钮,使故事出现在下一页。
首先,我想在收到“logline”和“plot”输入后实现下一个屏幕,但我不断得到这个错误

'NoneType' object has no attribute 'transition'.

你能解决这个问题吗?
先谢谢你解决了这个问题。我会接受你的建议的。
我想解决这个错误。

cyvaqqii

cyvaqqii1#

在应用程序的构建函数中,您需要创建一个ScreenManager并将小部件或屏幕添加到该ScreenManager。

class MyApp(App):
    def build(self):
        sm = ScreenManager()
        sm.add_widget(InputScreen(name='input'))
        return sm

相关问题