与Kivy在屏幕上的后退按钮

时间:2015-04-30 02:20:24

标签: python-2.7 kivy

我试图用kivy在屏幕上添加后退按钮。我正在寻找的是在屏幕上打印单词并插入后退按钮以返回到第一个屏幕

我目前正在做的事情:

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput

class InputSettings(GridLayout):

    def __init__(self, **kwargs):
        super(InputSettings, self).__init__(**kwargs)
        self.cols = 1
        self.add_widget(Label(text = "[b]Insert your email[/b]", markup = True, font_size = "40sp"))
        self.email_input = TextInput(multiline = False)

        self.add_widget(self.email_input)
        self.donebutton = Button(text = "Login", background_color = (0.2, 0.1, 0.2, 1.0))
        self.donebutton.bind(on_press = self._callback)
        self.add_widget(self.donebutton)

    def _callback(self, ev = None):
        if not len(self.email_input.text) > 4:
            self.clear_widgets()
            self.noinput = Label(text = "Please insert more information about your email !")
            self.add_widget(self.noinput)

            # here I want to add back button to return to first screen --> Insert your email

            self.backbotton = Button(text = "Back", background_color = (0, 1, 0, 1))
            self.backbotton.bind(on_press = InputSettings()) # I try (on_press = InputSettings()) but return with error
            self.add_widget(self.backbotton)
            return

## start

class Test(App):

    def build(self):
        return InputSettings()

if __name__ == "__main__":
    Test().run()

我该怎么做?

1 个答案:

答案 0 :(得分:1)

解决了:

添加screen1功能以插入信息并设置后退按钮以返回到screen1

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput


class InputSettings(GridLayout):

    def __init__(self, **kwargs):
        super(InputSettings, self).__init__(**kwargs)
        self.cols = 1
        self.screen1()

    def screen1(self, *args):
        self.clear_widgets()
        self.add_widget(Label(text = "[b]Insert your email[/b]", markup = True, font_size = "40sp"))
        self.email_input = TextInput(multiline = False)

        self.add_widget(self.email_input)
        self.donebutton = Button(text = "Login", background_color = (0.2, 0.1, 0.2, 1.0))
        self.donebutton.bind(on_press = self._callback)
        self.add_widget(self.donebutton)

    def _callback(self, ev = None):
        if not len(self.email_input.text) > 4:
            self.clear_widgets()
            self.noinput = Label(text = "Please insert more information about your email !")
            self.add_widget(self.noinput)

            self.backbotton = Button(text = "Back", background_color = (0, 1, 0, 1))
            self.backbotton.bind(on_press = self.screen1)
            self.add_widget(self.backbotton)
            return

## start

class Test(App):

    def build(self):
        return InputSettings()

if __name__ == "__main__":
    Test().run()
相关问题