我想在Kivy中創建一個簡單的應用程序,但我想將主顯示分爲兩部分。頂部會有一些按鈕,它會保持不變。但是,在底部我想在不同的屏幕之間切換。這可能嗎?Kivy的分屏?
下面是一個簡化版本:
<home screen>:
BoxLayout:
Button:
Screen:
(Switch between Screen 1, and 2)
<screen 1>
<screen 2>
我真的很感激一些幫助。謝謝!
好吧,這是我的非工作示例。
.py文件:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
class HomeScreen(Screen):
pass
class Screen1(Screen):
pass
class Screen2(Screen):
pass
class SplitScreenApp(App):
def build(self):
sm = ScreenManager()
sm.add_widget(HomeScreen(name='home_screen'))
sm.add_widget(Screen1(name='screen_one'))
sm.add_widget(Screen2(name='screen_two'))
return sm
if __name__ == "__main__":
SplitScreenApp().run()
.kv文件
<HomeScreen>:
BoxLayout:
orientation: 'vertical'
rows: 3
ScreenManager:
size_hint_y: 0.8
Button:
size_hint_y: 0.1
on_press:
root.manager.transition.direction = 'left'
root.manager.current = 'screen_one'
Button:
size_hint_y: 0.1
on_press:
root.manager.transition.direction = 'left'
root.manager.current = 'screen_two'
<Screen1>:
BoxLayout:
orientation: 'vertical'
rows: 1
Button:
text: "Screen 1"
<Screen2>:
BoxLayout:
orientation: 'vertical'
rows: 1
Button:
text: "Screen 2"
因此,我希望先看到兩個按鈕的頂部的 「畫面1」 節目。然後,我可以在「HomeScreen」中按下其中一個,並在按下時在「Screen 1」和「Screen 2」之間切換。
@inclement你能幫我修復我添加的代碼嗎? –