问题描述
main.py:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.uix.tabbedpanel import TabbedPanel
class Test(TabbedPanel):
pass
class MainWindow(Screen):
pass
class SecondWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("settings.kv")
class MyMainApp(App):
def build(self):
return kv
if __name__ == "__main__":
MyMainApp().run()
settings.kv:
WindowManager:
MainWindow:
SecondWindow:
Test:
<MainWindow>:
name: "main"
GridLayout:
cols:2
Button:
text: "New Order"
on_release:
app.root.current = "tabs"
root.manager.transition.direction = "left"
Button:
text: "Basket"
on_release:
app.root.current = "second"
root.manager.transition.direction = "left"
<SecondWindow>:
name: "second"
Button:
text: "Go Back"
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
<Test>:
name: "test"
size_hint: .5,.5
pos_hint: {'center_x': .5,'center_y': .5}
do_default_tab: False
TabbedPanelItem:
text: 'first tab'
Label:
text: 'First tab content area'
TabbedPanelItem:
text: 'tab2'
BoxLayout:
Label:
text: 'Second tab content area'
Button:
text: 'Button that does nothing'
TabbedPanelItem:
text: 'tab3'
RstDocument:
text:
'\\n'.join(("Hello world","-----------","You are in the third tab."))
我想要一个从按下按钮开始的过渡,这会导致选项卡式覆盖,但是屏幕管理器不接受使用选项卡式面板
kivy.uix.screenmanager.ScreenManagerException: ScreenManager accepts only Screen widget.
怎么才能达到这个效果,我是kivy新手。我想按一个按钮转到另一个正常屏幕,而另一个按钮打开选项卡式屏幕,
解决方法
只需将您的 TabbedPanel
放入 Screen
。
美好的一天。使用您的屏幕管理器在每个 screen 之间切换。然后屏幕包含您放置在其中的任何内容的独特布局。这可能包括带有标签的屏幕。