Kivy - 黑屏

时间:2017-09-18 16:52:24

标签: python kivy

为什么我会出现黑屏?该守则在10分钟前工作正常。 代码有什么问题,我看不出有什么不对!另外我在网上找不到任何解决方案!你们知道如何解决这个问题吗?

#!/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()

2 个答案:

答案 0 :(得分:0)

在通过'之后可能是缩进。在你的扫描功能。看起来' scanb',' title'等等,缩进了一个级别

答案 1 :(得分:0)

你有一些错误。有关详细信息,请参阅以下示例。

实施例

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()

输出

enter image description here