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

时间:2016-03-22 20:21:13

标签: python transition kivy

我正在使用不同的Screen做一个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()

0 个答案:

没有答案