如何在kivy python中以不同的方向进行屏幕转换?

如何在kivy python中以不同的方向进行屏幕转换?,python,transition,kivy,Python,Transition,Kivy,我正在使用不同的屏幕制作一个kivy应用程序,我想在不同的屏幕中向右或向左转换(这取决于它是第一个屏幕还是第二个屏幕)。如果有人知道如何进行转换,这将对我有帮助,我在这里附上我的应用程序代码 # -*- coding: utf-8 -*- from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import ScreenManager, Screen from kivy.uix.text

我正在使用不同的
屏幕制作一个kivy应用程序,我想在不同的屏幕中向右或向左转换(这取决于它是第一个屏幕还是第二个屏幕)。如果有人知道如何进行转换,这将对我有帮助,我在这里附上我的应用程序代码

# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.properties import DictProperty,ListProperty

Builder.load_string('''
<Root>:
    MainScreen:
        name: 'main'
    SecondScreen:
        name: 'second'


<MainScreen>:
    GridLayout:
        cols: 2
        Label:
            text: "Select Subjects (1/2)"
            font_size: 15
        Label:
            text: " "
        CheckBox:
            on_active:root.ping('240031',self.active)
        Label:
            text: "Electromagnetisme"
        CheckBox:
            on_active:root.ping('240033',self.active)
        Label:
            text: "Materials"
        CheckBox:
            on_active:root.ping('240052',self.active)
        Label:
            text: "Termodinàmica"
        CheckBox:
            on_active:root.ping('240053',self.active)
        Label:
            text: "Electrotècnia"
        CheckBox:
            on_active:root.ping('240054',self.active)
        Label:
            text: "Mecànica dels Medis Continus"
        CheckBox:
            on_active:root.ping('240061',self.active)
        Label:
            text: "Mecànica de Fluids"
        CheckBox:
            on_active:root.ping('240063',self.active)
        Label:
            text: "Resistència de Materials"

        Button:
            text: "Exit"
            background_color: .7, 1, 6, 1
            on_release:root.parent.current='second'
        Button:
            text: "Next"
            font_size: 
            background_color: .7, .7, 1, 1
            on_release: root.parent.current='second'
<SecondScreen>:
    GridLayout:
        cols: 2
        Label:
            text: "Select Subjects (2/2)"
            font_size: 15
        Label:
            text: " "
        CheckBox:
            on_active:root.ping('240072',self.active)
        Label:
            text: "Electrònica"
        CheckBox:
            on_active:root.ping('240073',self.active)
        Label:
            text: "Sistemes de Fabricació"
        CheckBox:
            on_active:root.ping('240151',self.active)
        Label:
            text: "Tecnologia i Selecció de Materials"
        CheckBox:
            on_active:root.ping('240161',self.active)
        Label:
            text: "Màquines Elèctriques"
        CheckBox:
            on_active:root.ping('240171',self.active)
        Label:
            text: "Termotècnia"
        CheckBox:
            on_active:root.ping('240172',self.active)
        Label:
            text: "Control Automàtic"
        Label:
            text: ""
        Label:
            text: ""
        Button:
            text: "Previous"
            background_color: .7, 1, 6, 1
            on_release:root.parent.current='main'
        Button:
            text: "exit"
            background_color: .7, .7, 1, 1
            on_release: root.parent.current='main'

''')


class MainScreen(Screen):
    def __init__(self, **kw):
        super(MainScreen, self).__init__(**kw)
        self.a = App.get_running_app()
        self.e={}
    def ping(self, n, value):
        self.a.big_dict[n] = value

class SecondScreen(Screen):
    def __init__(self, **kw):
        super(SecondScreen, self).__init__(**kw)
        self.a = App.get_running_app()
        self.e={}
        def ping(self, n, value):
            self.a.big_dict[n] = value
        def exit(self):
            return exit


class Root(ScreenManager):
    pass
class SimpleKivy(App):
    big_dict = DictProperty({'240161': False, '240061': False, '240171': False, '240151': False, '240063': False, '240073': False, '240072': False, '240031': False, '240033': False, '240054': False, '240053': False, '240052': False, '240172': False})
    def build(self):
        return Root()
SimpleKivy().run()
#-*-编码:utf-8-*-
从kivy.app导入应用程序
从kivy.lang导入生成器
从kivy.uix.screenmanager导入screenmanager,屏幕
从kivy.uix.textinput导入textinput
从kivy.uix.label导入标签
从kivy.uix.gridlayout导入gridlayout
从kivy.uix.button导入按钮
从kivy.properties导入DictProperty、ListProperty
Builder.load_字符串(“”)
:
主屏幕:
名称:'main'
第二屏:
姓名:“第二”
:
网格布局:
科尔斯:2
标签:
文本:“选择主题(1/2)”
字体大小:15
标签:
案文:“”
复选框:
on_active:root.ping('240031',self.active)
标签:
正文:“电磁学”
复选框:
on_active:root.ping('240033',self.active)
标签:
正文:“材料”
复选框:
on_active:root.ping('240052',self.active)
标签:
案文:“Termodinámica”
复选框:
on_active:root.ping('240053',self.active)
标签:
正文:“电子计算机”
复选框:
on_active:root.ping('240054',self.active)
标签:
正文:“Mecánica dels Medis continues”
复选框:
on_active:root.ping('240061',self.active)
标签:
案文:“流体的流动性”
复选框:
on_active:root.ping('240063',self.active)
标签:
文字:“材料抵抗”
按钮:
正文:“退出”
背景颜色:.7,1,6,1
发布时:root.parent.current='second'
按钮:
正文:“下一个”
字体大小:
背景颜色:.7、.7、1、1
发布时:root.parent.current='second'
:
网格布局:
科尔斯:2
标签:
文本:“选择主题(2/2)”
字体大小:15
标签:
案文:“”
复选框:
on_active:root.ping('240072',self.active)
标签:
文本:“Electrònica”
复选框:
on_active:root.ping('240073',self.active)
标签:
文本:“法布里卡奇体系”
复选框:
on_active:root.ping('240151',self.active)
标签:
文本:“技术与材料选择”
复选框:
on_active:root.ping('240161',self.active)
标签:
案文:“Máquines Elèctriques”
复选框:
on_active:root.ping('240171',self.active)
标签:
文本:“Termotècnia”
复选框:
on_active:root.ping('240172',self.active)
标签:
文本:“自动控制”
标签:
案文:“”
标签:
案文:“”
按钮:
案文:“以前”
背景颜色:.7,1,6,1
发布时:root.parent.current='main'
按钮:
正文:“退出”
背景颜色:.7、.7、1、1
发布时:root.parent.current='main'
''')
类主屏幕(屏幕):
def初始功率(自身功率,**kw):
超级(主屏幕,自)
self.a=App.get_running_App()
self.e={}
def ping(自身、n、值):
self.a.big_dict[n]=值
第二类屏幕(屏幕):
def初始功率(自身功率,**kw):
超级(第二屏,自)
self.a=App.get_running_App()
self.e={}
def ping(自身、n、值):
self.a.big_dict[n]=值
def出口(自):
回程出口
类根(屏幕管理器):
通过
SimpleKivy类(应用程序):
big_dict=DictProperty({240161':False,'240061':False,'240171':False,'240151':False,'240063':False,'240073':False,'240072':False,'240031':False,'240033':False,'240054':False,'240053':False,'240052':False,'240172':False})
def生成(自):
返回根()
SimpleKivy().run()

您似乎只在
kv
代码中更改屏幕。本例在按钮中添加
root.manager.transition.direction='left'
无效。我试过使用上一个
按钮
,但按下按钮后仍然会向右移动。这是因为屏幕管理器在代码中是以
root.parent
的身份访问的。就像现有的handlersOkay一样,我使用了错误的方向。如果我想通过
kv
语言中的按钮退出,我该怎么做
root.parent.current=exit
不起作用。谢谢,请自己学习教程、文档和示例。你好像不知道自己在做什么。。。