简体   繁体   English

Kivy-获得黑屏

[英]Kivy - Getting Black Screen

Why am i getting a black screen? 为什么我会出现黑屏? The Code worked fine 10 minutes ago. 守则在10分钟前运作良好。 What's wrong with the Code, i cannot see anything wrong! 准则有什么问题,我看不到任何错误! Also i cannot find any solution for that online! 我也找不到在线的任何解决方案! Do you guys know how to fix the Problem? 你们知道如何解决问题吗?

#!/usr/bin/env python

import kivy

kivy.require("1.10.0")

import os
import humanize
from glob import glob
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout

class Layout(GridLayout):
    def __init__(self,**kwargs):
        super(Layout,self).__init__(**kwargs)
        self.cols = 1

     def scan(self):
        pass          
        scanb = Button(text="Scan",background_color=(1,0,1,1),font_size=(50))
        title = Label(text="StorageCleaner",font_size=(50),size_hint=(.1,.2),background_color=(1,0,0,1))

        self.add_widget(title)
        self.add_widget(copy)
        scanb.bind(on_press=scan)

class StorageCleaner(App):
    def build(self):
        layout = Layout()
        return layout

sc = StorageCleaner()

if __name__ == "__main__":
       sc.run()

Might be the indentation after 'pass' in your scan function. 可能是扫描功能“通过”后的缩进。 Looks like 'scanb', 'title', etc, is indented one level too much 看起来'scanb','title'等缩进了一个级别

You have a few errors. 您有一些错误。 Please refer to the example below for details. 有关详细信息,请参见以下示例。

Example

main.py main.py

import kivy
kivy.require("1.10.0")

import os
import humanize
from glob import glob
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout


class Layout(GridLayout):

    def __init__(self, **kwargs):
        super(Layout, self).__init__(**kwargs)

        self.cols = 1

        scanb = Button(text="Scan", font_size=50)
        scanb.bind(on_press=self.scan)
        title = Label(text="StorageCleaner", font_size=50, size_hint=(.1, .2))

        self.add_widget(title)
        self.add_widget(scanb)

    def scan(self):
        pass


class StorageCleaner(App):

    def build(self):
        return Layout()


if __name__ == "__main__":
    StorageCleaner().run()

Output 输出量

在此处输入图片说明

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

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