-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentdb.py
76 lines (50 loc) · 2.19 KB
/
studentdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# ---------- KIVY TUTORIAL PT 4 ----------
# In this part of my Kivy tutorial I'll show how to use
# the ListView, ListAdapter and how to create a toolbar
# ---------- studentdb.py ----------
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.listview import ListItemButton
class StudentListButton(ListItemButton):
pass
class StudentDB(BoxLayout):
# Connects the value in the TextInput widget to these
# fields
first_name_text_input = ObjectProperty()
last_name_text_input = ObjectProperty()
student_list = ObjectProperty()
def submit_student(self):
# Get the student name from the TextInputs
student_name = self.first_name_text_input.text + " " + self.last_name_text_input.text
# Add the student to the ListView
self.student_list.adapter.data.extend([student_name])
# Reset the ListView
self.student_list._trigger_reset_populate()
def delete_student(self, *args):
# If a list item is selected
if self.student_list.adapter.selection:
# Get the text from the item selected
selection = self.student_list.adapter.selection[0].text
# Remove the matching item
self.student_list.adapter.data.remove(selection)
# Reset the ListView
self.student_list._trigger_reset_populate()
def replace_student(self, *args):
# If a list item is selected
if self.student_list.adapter.selection:
# Get the text from the item selected
selection = self.student_list.adapter.selection[0].text
# Remove the matching item
self.student_list.adapter.data.remove(selection)
# Get the student name from the TextInputs
student_name = self.first_name_text_input.text + " " + self.last_name_text_input.text
# Add the updated data to the list
self.student_list.adapter.data.extend([student_name])
# Reset the ListView
self.student_list._trigger_reset_populate()
class StudentDBApp(App):
def build(self):
return StudentDB()
dbApp = StudentDBApp()
dbApp.run()