简体   繁体   English

在猕猴桃中得到黑屏

[英]getting black screen in kivy

i am running this kivy app and it is just giving me a black window! 我正在运行这个kivy应用程序,它只是给了我一个黑色的窗口! What is the problem? 问题是什么? I searched for a solution here and I didn't find something. 我在这里搜索解决方案,但没有找到任何东西。 this is the kivy file this is the python code 这是kivy文件, 这是python代码

First of all, you need to post your code as text so people can actually copy paste it into their editors. 首先,您需要将代码以文本形式发布,以便人们可以将其复制并粘贴到他们的编辑器中。

However, you are getting black screen because you have your code in __init__() method of the App class, move that code to build() method and you are good to go. 但是,由于您的代码位于App类的__init__()方法中,请将代码移至build()方法中,您就可以使用了。 For example: 例如:

class TestApp(App):

    def build(self):
        self.sm = ScreenManager()
        self.sm.add_widget(MainScreen(name='main'))
        # and so on
        return self.sm

Why? 为什么?

You are calling TestApp().run() without creating an instance of the class so __init__() is never called. 您在调用TestApp().run()没有创建该类的实例,因此永远不会调用__init__() __init__() method is called only when you create an instance of the class. __init__()方法仅在创建类的实例时被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM