我有一个简单的测试程序:
主文件
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.screenmanager import Screen
from kivy.clock import mainthread
class TestScreen(Screen):
@mainthread
def on_pre_enter(self): #Is loaded before kv buttons etc? how make it work
pass
@mainthread
def on_enter(self): #Load after kv buttons etc?
button = Button(text="Work?")
#how now add it to display?
#how control where display it? on end or begin is just about on_pre and on?
class TestApp(App):
pass
if __name__ == '__main__':
TestApp().run()
和 test.kv 文件
#:import NoTransition kivy.uix.screenmanager.NoTransition
<TestScreen>:
name:'try'
GridLayout:
id:'test'
cols:2
Button:
text:'Test'
on_press:app.root.current='Main'
ScreenManager:
transition: NoTransition()
Screen:
name: 'Main'
GridLayout:
cols:1
Button:
text:'1'
Button:
text:'2'
Button:
text:'Test'
on_press:root.current='try'
TestScreen:
控制 kv 和 python 小部件很简单(但我不知道如何在 kv 文件中编写小部件等更容易,但仍然需要在 python 中创建一些用于自动内容)或者更好地在没有 kv 文件的情况下在 python 中创建所有内容?我想做这样的事情:始终显示左侧菜单的应用程序,而在右侧另一个具有基于屏幕的动态内容的屏幕(从菜单中单击)可能是另一个简单的解决方案。任何人都可以逐步解释我吗?:)