Advertisement
furas

Python - Kivy - TextInput, Button

May 16th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. import kivy
  2. from kivy.app import App
  3. from kivy.uix.gridlayout import GridLayout
  4. from kivy.uix.label import Label
  5. from kivy.uix.textinput import TextInput
  6. from kivy.uix.button import Button
  7.  
  8.  
  9. class LoginScreen(GridLayout):
  10.  
  11.     def __init__(self, **kwargs):
  12.         super(LoginScreen, self).__init__(**kwargs)
  13.         self.cols = 2
  14.         self.add_widget(Label(text='Livro1:'))
  15.         self.bookone = TextInput(multiline=False)
  16.         self.add_widget(self.bookone)
  17.  
  18.         self.add_widget(Label(text='Livro2:'))
  19.         self.booktwo = TextInput(multiline=False)
  20.         self.add_widget(self.booktwo)
  21.  
  22.         self.add_widget(Button(text='Submit2', on_press=self.callback ))
  23.         self.add_widget(Button(text='Submit1', on_press=self.callback ))
  24.  
  25.     def callback(self, args): # need self, args
  26.         print('[DEBUG] args:', args)
  27.         print('[DEBUG] args.text:', args.text)
  28.        
  29.         if args.text == 'Submit1':
  30.             txt = self.bookone.text # get text from input
  31.         elif args.text == 'Submit2':
  32.             txt = self.booktwo.text # get text from input
  33.         else:
  34.             txt = '???'
  35.            
  36.         print('I am being pressed', args.text, txt)
  37.        
  38.        
  39. class MyApp(App):
  40.  
  41.     def build(self):
  42.         return LoginScreen()
  43.  
  44.  
  45. if __name__ == '__main__':
  46.     MyApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement