猕猴桃不能使用kv文件

时间:2018-08-18 14:12:58

标签: python kivy kivy-language

我在custom.kv文件中定义了CustomButton和CustomWidget, 在main.py中定义了空的CustomWidget类,但是当我运行该程序时,窗口全是黑色的,没有按钮。我在做什么错了?

main.py

import kivy
kivy.require('1.10.1')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button

class CustomWidget(Widget):
    pass

class CustomButton(Button):
    pass

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


application = MyApp()
application.run()

custom.kv

#:kivy 1.10.1

<CustomButton@Button>:
    font_size: 32
    color: .5, .5, 0, 1
    size: 150, 50
    background_normal: ''
    background_down: 'background.png'
    background_color: .88, .88, .88, 1

<CustomWidget>:
    CustomButton:
        text: 'Random'
        pos: root.x, 200

输出:

black window

0 个答案:

没有答案