【问题标题】:Blank screen in screen manager kivy屏幕管理器kivy中的空白屏幕
【发布时间】:2015-10-31 20:40:57
【问题描述】:

请帮我看看这段代码。每次运行它,它都会显示一个空白屏幕,我是 kivy 的新手。

from kivy.app import App
from kivy.uix.widget import Widget 
from kivy.uix.button import Button
from kivy.uix.screenmanager import           ScreenManager,Screen 
from kivy.lang import Builder 


class first_screen(Screen):
    pass

class second_screen(Screen):
    pass 

class my_manager(ScreenManager):
    pass 


Builder.load_file("testing_screens.kv")

class testing_screens(App):
    def build(self):
        return my_manager()



testing_screens().run()


<my_manager>:
    first_screen:
    second_screen:

<first_screen>:
    name: "one"
    Button:
        text: "hello peeps"
        on_press: app.root.current= "two"

<second_screen>:
    name: "two"
    Button:
        text: "world gurus"
        on_press: app.root.current= "one"

代码搞砸了。

【问题讨论】:

    标签: kivy


    【解决方案1】:

    小部件名称必须以大写字母开头才能使 kv 起作用,因为它使用它来区分它们与属性。在这种情况下,kv 规则认为您创建了两个名为 first_screen 和 second_screen 的新属性,而不是您添加了两个小部件。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多