Advertisement
agenor91

studentdb

Feb 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.09 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.uix.boxlayout import BoxLayout
  3. from kivy.properties import ObjectProperty
  4. from kivy.uix.listview import ListItemButton
  5.  
  6.  
  7. class StudentListButton(ListItemButton):
  8.     pass
  9.  
  10.  
  11. class StudentDB(BoxLayout):
  12.  
  13.     # Connects the value in the TextInput widget to these
  14.     # fields
  15.     first_name_text_input = ObjectProperty()
  16.     last_name_text_input = ObjectProperty()
  17.     student_list = ObjectProperty()
  18.  
  19.     def submit_student(self):
  20.  
  21.         # Get the student name from the TextInputs
  22.         student_name = self.first_name_text_input.text + " " + self.last_name_text_input.text
  23.  
  24.         # Add the student to the ListView
  25.         self.student_list.adapter.data.extend([student_name])
  26.  
  27.         # Reset the ListView
  28.         self.student_list._trigger_reset_populate()
  29.  
  30.     def delete_student(self, *args):
  31.  
  32.         # If a list item is selected
  33.         if self.student_list.adapter.selection:
  34.  
  35.             # Get the text from the item selected
  36.             selection = self.student_list.adapter.selection[0].text
  37.  
  38.             # Remove the matching item
  39.             self.student_list.adapter.data.remove(selection)
  40.  
  41.             # Reset the ListView
  42.             self.student_list._trigger_reset_populate()
  43.  
  44.     def replace_student(self, *args):
  45.  
  46.         # If a list item is selected
  47.         if self.student_list.adapter.selection:
  48.  
  49.             # Get the text from the item selected
  50.             selection = self.student_list.adapter.selection[0].text
  51.  
  52.             # Remove the matching item
  53.             self.student_list.adapter.data.remove(selection)
  54.  
  55.             # Get the student name from the TextInputs
  56.             student_name = self.first_name_text_input.text + " " + self.last_name_text_input.text
  57.  
  58.             # Add the updated data to the list
  59.             self.student_list.adapter.data.extend([student_name])
  60.  
  61.             # Reset the ListView
  62.             self.student_list._trigger_reset_populate()
  63.  
  64.  
  65. class StudentDBApp(App):
  66.     def build(self):
  67.         return StudentDB()
  68.  
  69.  
  70. dbApp = StudentDBApp()
  71.  
  72. dbApp.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement