是否可以通过动作交换屏幕,而不是按下按钮?我在移动应用程序的上下文中询问,用户经常期望这种行为。
答案 0 :(得分:2)
您可以使用Carousel小部件。例如:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
Builder.load_string("""
<MyWidget>:
Carousel:
BoxLayout:
orientation: 'vertical'
Label:
text: "Screen 1"
Label:
text: "Some text"
BoxLayout:
orientation: 'vertical'
Label:
text: "Screen 2"
BoxLayout:
Button:
text: "1"
Button:
text: "2"
Button:
text: "3"
Button:
text: "4"
BoxLayout:
orientation: 'vertical'
Label:
text: "Screen 3"
Label:
text: "Some other text"
""")
class MyWidget(BoxLayout):
pass
class MyApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
MyApp().run()
答案 1 :(得分:2)
我认为这可能是更好的做事方式:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.carousel import Carousel
from kivy.lang import Builder
Builder.load_string("""
<MyCarousel>:
BoxLayout:
orientation: 'vertical'
Label:
text: "Screen 1"
Label:
text: "Some text"
BoxLayout:
orientation: 'vertical'
Label:
text: "Screen 2"
BoxLayout:
Button:
text: "1"
Button:
text: "2"
Button:
text: "3"
Button:
text: "4"
BoxLayout:
orientation: 'vertical'
Label:
text: "Screen 3"
Label:
text: "Some other text"
""")
class MyCarousel(Carousel):
pass
class MyApp(App):
def build(self):
return MyCarousel()
if __name__ == '__main__':
MyApp().run()
显然,Carousel的行为与其他小部件不同,因为它的默认大小不是100,100。