I would like to implement a kivy application, which has two screens (managed by a screen manager). On the first screen (called LoginScreen) there are two TextInput fields and a button. On the second screen I have two labels, which I would like to display the values, entered on the first screen. Changing the screens is done after button click.
I managed to bind these fields together so the values are displayed on the second screen. However, I would like to "process" these values in the second screen, which, unfortunately, I haven't been able to do.
By "process" I mean, that I would like to login to my e-mail account using a custom-built class (which is working) and list my unseen emails (which are provided by one of the class' function) in a kivy list.
Could, someone please tell me how I could get the entered values and use them to create my class?
I would greatly appreciate any help!
My .py file:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ListProperty, StringProperty
class MainScreenManager(ScreenManager):
pass
class LoginScreen(Screen):
entered_email_address = StringProperty('')
entered_password = StringProperty('')
def check_input(self):
text_input_email = self.ids['ti_email'].text
text_input_password = self.ids['ti_password'].text
self.entered_email_address = text_input_email
self.entered_password = text_input_password
"""
the values in this part are printed out
print self.manager
print self.manager.screens
print self.manager.get_screen('HomeScreen').email_address
print self.manager.get_screen('HomeScreen').password
"""
self.manager.current = 'HomeScreen'
class HomeScreen(Screen):
email_address = StringProperty()
password = StringProperty()
def __init__(self, *args, **kwargs):
super(HomeScreen, self).__init__(*args, **kwargs)
class TutorialApp(App):
def build(self):
return MainScreenManager()
if __name__ == '__main__':
TutorialApp().run()
My .kv file:
<MainScreenManager>:
id: screen_manager
LoginScreen:
id: login_screen
name: 'LoginScreen'
manager: screen_manager
HomeScreen:
id: home_screen
name: 'HomeScreen'
email_address: login_screen.entered_email_address
password: login_screen.entered_password
<LoginScreen>
BoxLayout:
orientation: 'vertical'
TextInput:
id: ti_email
multiline: False
size_hint_y: None
height: 40
font_size: 25
TextInput:
id: ti_password
multiline: False
size_hint_y: None
height: 40
font_size: 25
Button:
id: btn_login
text: 'Login!'
height: 100
width: 150
on_press:
root.check_input()
<HomeScreen>
BoxLayout:
orientation: 'vertical'
Label:
text: root.email_address
Label:
text: root.password