Kivy命名规则

1、类继承App的类名(小写)(除去App)+ .kv
例如:

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.graphics import Color,Rectangle
from kivy.properties import ColorProperty, ListProperty


class LoginScreen(GridLayout):
    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs)
        self.cols = 2
        self.rows = 6
        self.add_widget(Label(text='User Name'))
        self.username = TextInput(multiline=False)
        self.add_widget(self.username)
        self.add_widget(Label(text='password'))
        self.password = TextInput(password=True, multiline=False)
        self.add_widget(self.password)
        self.button = Button(size=(.4, .63), text='iPaoMi', background_color=(0, 0, 1), font_size=15, color=(1, 0, 1))
        self.button.bind(on_press=self.on_push)

        self.add_widget(self.button)

        with self.password.canvas.before:
            Color(1, 0.5, 0, 0.5)
            self.password = Rectangle(size=self.password.size, pos=self.password.pos)

    def on_push(self, inst):
        print('inst'+inst.text)
        self.button.text = inst.text
        self.button.height=12


class MyApp(App):
    def build(self):
        self.root = root = LoginScreen()
        return root


if __name__ == '__main__':
    MyApp().run()

创建的kv文件则为 my.kv
代码分离规则:
定义页面:

使用`<>:`创建一个页面,页面和py里的类一致。
例如:
    且使用缩进标识控件和属性的隶属关系。
<LoginScreen>:
    BoxLayout:
        Button:
    BoxLayout:
        Button:
<LoginScreen>:

使用kv文件则无须使用Py文件进行编写布局,可直接如下:

class LoginScreen(App):
    pass