几个月不写中文了, 感觉还行。 So, let's begin our journey.
首先,有两个网址你不得不看:
Kivy总体思想是:kv代码管界面,python代码管逻辑。
然后重点来了, 我主要讲三件事:(kv访问Python;Python访问kv;窗口)。
一阶段:
1.Python访问kv
Python可以直接调用kv代码。如:
from kivy.app import App
from kivy.lang import Builder
kv = Builder.load_string('''
Button:
text: "I was created by kv codes"
''')
class TestApp(App):
def build(self):
return kv
TestApp().run()
2.窗口
kv代码中被<>包裹住的是某个class的名字,这个class需在python代码中声明,它们代表同一个class。
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
Builder.load_string('''
Label:
text: "My mother screen was created by kv and python codes."
''')
class OneScreen(Screen):
pass
class TestApp(App):
def build(self):
return OneScreen()
TestApp().run()
3. kv访问Python
在.kv文件或kv代码里,root只代表其上层被<>包裹住的类。如:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
Builder.load_string('''
Button:<