我正在尝试使用CardTransition在多个屏幕上创建一个简单的应用程序,但是当我尝试运行它时,我得到一个错误。我知道应用程序本身有效,因为我尝试了不同的过渡,它工作正常。我正在使用Python 3.4.4和Kivy 1.9.1。
以下是代码:
import kivy
kivy.require("1.9.1")
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, SwapTransition, CardTransition
KivyFile = Builder.load_string("""
<Screen1>:
name: "Screen1"
BoxLayout:
orientation: "vertical"
padding: 40
spacing: 20
Label:
text: "This is screen 1"
Button:
text: "Next Screen"
on_release: app.root.current = "Screen2"
<Screen2>:
name: "Screen2"
BoxLayout:
orientation: "vertical"
padding: 40
spacing: 20
Label:
text: "This is screen 2"
Button:
text: "Next Screen"
on_release: app.root.current = "Screen3"
<Screen3>:
name: "Screen3"
BoxLayout:
orientation: "vertical"
padding: 40
spacing: 20
Label:
text: "This is screen 3"
Button:
text: "Next Screen"
on_release: app.root.current = "Screen1"
""")
class Screen1(Screen):
pass
class Screen2(Screen):
pass
class Screen3(Screen):
pass
sm = ScreenManager(transition=CardTransition())
sm.add_widget(Screen1(name = "Screen1"))
sm.add_widget(Screen2(name = "Screen2"))
sm.add_widget(Screen3(name = "Screen3"))
class MyApp(App):
def build(self):
return sm
if __name__ == "__main__":
MyApp().run()
这是我得到的错误:
Traceback (most recent call last):
File "C:/Users/Markus/Desktop/Kivy/TestTransitions.py", line 9, in <module>
from kivy.uix.screenmanager import ScreenManager, Screen, SwapTransition, CardTransition
ImportError: cannot import name 'CardTransition'
答案 0 :(得分:0)
CardTransition只在kivy 1.10中添加。