0
1
00:00:04,260 --> 00:00:05,600
<v ->Hello again,</v>
1

2
00:00:05,600 --> 00:00:07,920
In previous lecture what we did.
2

3
00:00:07,920 --> 00:00:11,750
We learnt how we can display our persons at our list box,
3

4
00:00:11,750 --> 00:00:12,583
right?
4

5
00:00:12,583 --> 00:00:14,340
And now in this lecture we going to learn
5

6
00:00:14,340 --> 00:00:16,450
how we can update our database,
6

7
00:00:16,450 --> 00:00:18,370
how we can update our persons,
7

8
00:00:18,370 --> 00:00:20,650
to do that what I need to do here.
8

9
00:00:20,650 --> 00:00:22,140
Our update button is here, right?
9

10
00:00:22,140 --> 00:00:24,650
Btupdate and here what I need to do
10

11
00:00:24,650 --> 00:00:26,507
I will to say here,
11

12
00:00:26,507 --> 00:00:30,603
command let's take it to here first.
12

13
00:00:31,660 --> 00:00:34,650
Command is equal to my function
13

14
00:00:34,650 --> 00:00:35,483
so I will say,
14

15
00:00:35,483 --> 00:00:37,497
self.funcUpdatePerson okay?
15

16
00:00:41,400 --> 00:00:42,860
This is my function name.
16

17
00:00:42,860 --> 00:00:45,363
Now what I need to do, I need to create this function right?
17

18
00:00:45,363 --> 00:00:47,150
to do that I will come here
18

19
00:00:47,150 --> 00:00:51,930
and say my definition and after that my function name
19

20
00:00:51,930 --> 00:00:53,520
Okay this is okay.
20

21
00:00:53,520 --> 00:00:55,113
And here what I need to do.
21

22
00:00:56,750 --> 00:00:59,910
Firstly let's say pass, okay?
22

23
00:00:59,910 --> 00:01:01,220
I want to show you something,
23

24
00:01:01,220 --> 00:01:04,000
here lets go to back to main.py
24

25
00:01:04,000 --> 00:01:06,423
and here I will run my main.py
25

26
00:01:08,290 --> 00:01:09,123
my people.
26

27
00:01:09,123 --> 00:01:12,770
For example here if I want to update, Adam
27

28
00:01:12,770 --> 00:01:15,420
what I will do i need to click update button right?
28

29
00:01:15,420 --> 00:01:19,340
But noting happens now of course because we didn't.
29

30
00:01:19,340 --> 00:01:21,630
Our function is empty right?
30

31
00:01:21,630 --> 00:01:26,630
What I need to do here we have a number right?
31

32
00:01:27,510 --> 00:01:30,480
Actually this is ID, name and surname.
32

33
00:01:30,480 --> 00:01:32,570
If I want to update a person
33

34
00:01:32,570 --> 00:01:36,070
what I need to do, I need to use something unique okay?
34

35
00:01:36,070 --> 00:01:37,620
This unique thing is.
35

36
00:01:37,620 --> 00:01:40,710
It cannot be name or surname because some people
36

37
00:01:42,852 --> 00:01:46,550
they can have same names or same surnames right?
37

38
00:01:46,550 --> 00:01:48,640
So I need to use something unique
38

39
00:01:48,640 --> 00:01:52,620
unique thing is here only it's my ID okay?
39

40
00:01:52,620 --> 00:01:54,730
So when I click this guy and after,
40

41
00:01:54,730 --> 00:01:58,705
if I say update I will get all of this,
41

42
00:01:58,705 --> 00:02:00,710
for example 2-Adam Black, okay?.
42

43
00:02:00,710 --> 00:02:03,490
And after, what I need to do, how I can get this ID.
43

44
00:02:03,490 --> 00:02:04,660
I will use a function to get only ID
44

45
00:02:06,061 --> 00:02:07,675
and after that will go to database
45

46
00:02:07,675 --> 00:02:11,500
and I will tell the database, hey my database, this is my ID
46

47
00:02:11,500 --> 00:02:16,500
and I want to update the person which has this ID, okay?
47

48
00:02:16,720 --> 00:02:18,483
So, let's go back to our,
48

49
00:02:19,590 --> 00:02:23,360
my people function, my people file.
49

50
00:02:23,360 --> 00:02:28,360
Okay, here what I will say, I need to say, selected item.
50

51
00:02:28,680 --> 00:02:33,680
I need to get my person, right?
51

52
00:02:33,790 --> 00:02:36,387
selected item is equal to self.listBox
52

53
00:02:39,400 --> 00:02:41,753
and here what I need to do, I need to say,
53

54
00:02:41,753 --> 00:02:44,330
curSelection, okay this function.
54

55
00:02:44,330 --> 00:02:45,583
And after that, what I need to do,
55

56
00:02:45,583 --> 00:02:49,896
I'll say, person is equal to
56

57
00:02:49,896 --> 00:02:53,410
self.listBox.get
57

58
00:02:53,410 --> 00:02:57,230
and here I will pass in selected item, okay?
58

59
00:02:57,230 --> 00:02:58,930
Now, If I.
59

60
00:02:58,930 --> 00:03:00,980
Actually, let's use print function first.
60

61
00:03:00,980 --> 00:03:03,677
Print person, okay?
61

62
00:03:03,677 --> 00:03:05,427
Now, If I run my application.
62

63
00:03:09,050 --> 00:03:13,130
My people and Adam and update, right?
63

64
00:03:13,130 --> 00:03:15,120
Now, let's see here.
64

65
00:03:15,120 --> 00:03:18,290
Our ID is here after that, name and surname.
65

66
00:03:18,290 --> 00:03:21,670
So I need ID here, how can I get this ID.
66

67
00:03:21,670 --> 00:03:24,440
To do that, I need to use split function okay?
67

68
00:03:24,440 --> 00:03:25,693
And here I will say,
68

69
00:03:27,960 --> 00:03:32,960
person ID is equal to person.split,
69

70
00:03:35,070 --> 00:03:39,250
but I will split by of course dash, okay this one.
70

71
00:03:39,250 --> 00:03:41,920
And after that, Python will return me
71

72
00:03:41,920 --> 00:03:46,050
a list the first item, at first index will be my ID
72

73
00:03:46,050 --> 00:03:50,550
and at second index, index one will be name and surname.
73

74
00:03:50,550 --> 00:03:54,330
Okay, so here I will say, dash, okay?
74

75
00:03:54,330 --> 00:03:58,310
Now, if I want to get only the ID here, what I need to do.
75

76
00:03:58,310 --> 00:04:02,560
I need to come here and say, first index, okay?
76

77
00:04:02,560 --> 00:04:07,190
So, it is zero because if I run now, this one for example,
77

78
00:04:07,190 --> 00:04:08,240
you'll understand it better.
78

79
00:04:08,240 --> 00:04:10,700
Person ID, right?
79

80
00:04:10,700 --> 00:04:15,190
Person ID will be, actually not that one because we used.
80

81
00:04:15,190 --> 00:04:16,980
Let's delete this one first, okay?
81

82
00:04:16,980 --> 00:04:18,643
And after that we can.
82

83
00:04:19,580 --> 00:04:23,180
Again, use index, here run
83

84
00:04:23,180 --> 00:04:26,410
and my people, Adam, update.
84

85
00:04:26,410 --> 00:04:29,300
You see now, this a list, I only need here this guy.
85

86
00:04:29,300 --> 00:04:32,010
So, this is at index zero, okay?
86

87
00:04:32,010 --> 00:04:33,633
That's why here I'll say,
87

88
00:04:37,120 --> 00:04:40,000
first index, okay?
88

89
00:04:40,000 --> 00:04:42,250
And now I have my ID right?
89

90
00:04:42,250 --> 00:04:46,540
So, what I need to do, now I will create a new class, okay?
90

91
00:04:46,540 --> 00:04:48,350
I will not create a new Python file,
91

92
00:04:48,350 --> 00:04:51,030
why it's like that because we should also learn
92

93
00:04:51,030 --> 00:04:53,700
how we can work will multiple classes okay?
93

94
00:04:53,700 --> 00:04:55,620
Sometimes, we need to use multiple files
94

95
00:04:55,620 --> 00:04:59,100
or sometimes we need to use multiple classes in our file.
95

96
00:04:59,100 --> 00:05:02,440
So, for this case I will create another class, okay?
96

97
00:05:02,440 --> 00:05:05,513
And here, how can I create a class, I will say,
97

98
00:05:07,200 --> 00:05:12,200
for update page, update page or window, doesn't matter,
98

99
00:05:12,220 --> 00:05:16,520
is equal to a class name, my class name will be update okay?
99

100
00:05:16,520 --> 00:05:18,750
But we didn't create this class yet, right?
100

101
00:05:18,750 --> 00:05:21,730
So, how can I do that, I will come here and say,
101

102
00:05:21,730 --> 00:05:25,523
class and update, okay?
102

103
00:05:27,300 --> 00:05:31,680
And here, what I need to do, if I want to create update.
103

104
00:05:31,680 --> 00:05:35,730
Here I will use, I will inherit it again, Toplevel okay?
104

105
00:05:35,730 --> 00:05:40,503
And here I will say, Toplevel and after that,
105

106
00:05:41,580 --> 00:05:44,330
by the way we don't have error now you see?
106

107
00:05:44,330 --> 00:05:49,120
And here, what I need to say, I need to say def init
107

108
00:05:49,120 --> 00:05:50,943
underscore, underscore, init.
108

109
00:05:52,530 --> 00:05:55,047
And after that also I need to say,
109

110
00:05:55,047 --> 00:05:58,190
Toplevel.geometry,
110

111
00:05:58,190 --> 00:05:59,190
sorry, Toplevel.init
111

112
00:06:02,850 --> 00:06:04,500
and again self, right?
112

113
00:06:04,500 --> 00:06:06,050
And here what I will say,
113

114
00:06:06,050 --> 00:06:09,770
self.geometry for geometry,
114

115
00:06:09,770 --> 00:06:14,053
I will say 650 same values actually I will use
115

116
00:06:15,098 --> 00:06:18,497
650 by 750, okay.
116

117
00:06:20,210 --> 00:06:24,087
And after that plus 550 and 200.
117

118
00:06:25,930 --> 00:06:30,483
For title, let's say, self.title,
118

119
00:06:32,480 --> 00:06:34,587
self.title will be Update,
119

120
00:06:38,180 --> 00:06:42,250
Update Person, okay?
120

121
00:06:42,250 --> 00:06:44,963
And the last thing what will be we also can use,
121

122
00:06:46,822 --> 00:06:50,697
self.resizable, resizable will false and false.
122

123
00:06:53,710 --> 00:06:57,230
Okay, now we are ready, we already created our window.
123

124
00:06:57,230 --> 00:07:00,520
But what I need to do, here if I run my application,
124

125
00:07:00,520 --> 00:07:02,410
let's see our window first,
125

126
00:07:02,410 --> 00:07:06,920
Run, my people, David this time, update.
126

127
00:07:06,920 --> 00:07:08,790
As you see now, our window is here.
127

128
00:07:08,790 --> 00:07:11,210
So, what we need to do, we need to create our design
128

129
00:07:11,210 --> 00:07:12,880
for this window right?
129

130
00:07:12,880 --> 00:07:17,310
And to do that, actually I will make it in next lesson
130

131
00:07:17,310 --> 00:07:18,730
and here in this lesson,
131

132
00:07:18,730 --> 00:07:23,730
let's get our person from our database okay?
132

133
00:07:24,120 --> 00:07:25,910
So, this is also very important, what we need to do
133

134
00:07:25,910 --> 00:07:27,930
if you want to update someone,
134

135
00:07:27,930 --> 00:07:29,520
you need to get this person
135

136
00:07:29,520 --> 00:07:33,020
from database display in your window
136

137
00:07:33,020 --> 00:07:36,730
and after that, you need to update this guy, right?
137

138
00:07:36,730 --> 00:07:39,374
To that what I will say here,
138

139
00:07:39,374 --> 00:07:41,913
by the way we need to use here global ID
139

140
00:07:42,960 --> 00:07:47,623
and here let's say, get person from database.
140

141
00:07:48,930 --> 00:07:53,930
And what I mean, using global ID.
141

142
00:07:54,310 --> 00:07:57,240
Now here, let's go back to our update person,
142

143
00:07:57,240 --> 00:07:58,960
it's here, our ID.
143

144
00:07:58,960 --> 00:08:00,950
I need this ID, okay this is important
144

145
00:08:00,950 --> 00:08:02,800
but this is in another class.
145

146
00:08:02,800 --> 00:08:05,250
Our class name is my people, right?
146

147
00:08:05,250 --> 00:08:07,903
So, if I want to use this ID in this class,
147

148
00:08:08,880 --> 00:08:10,920
what I need to do, I need to use.
148

149
00:08:10,920 --> 00:08:14,240
Of course we have some ways, but I think for this case
149

150
00:08:14,240 --> 00:08:17,050
the best one is using global key word.
150

151
00:08:17,050 --> 00:08:19,430
To do that I will come here and say,
151

152
00:08:19,430 --> 00:08:23,660
global person ID, okay?
152

153
00:08:23,660 --> 00:08:25,350
Now, but it's not enough.
153

154
00:08:25,350 --> 00:08:30,350
If I come here and if I say, for example person ID.
154

155
00:08:31,590 --> 00:08:33,130
This is variable.
155

156
00:08:33,130 --> 00:08:36,170
This person ID, it is not there, they are not the same thing
156

157
00:08:36,170 --> 00:08:37,950
because Python cannot understand.
157

158
00:08:37,950 --> 00:08:41,520
This can be another person ID, it's another class.
158

159
00:08:41,520 --> 00:08:43,520
So, that's why here you need to say,
159

160
00:08:43,520 --> 00:08:47,260
hey Python this is same one, this is global person ID.
160

161
00:08:47,260 --> 00:08:48,710
So they are now same, okay.
161

162
00:08:48,710 --> 00:08:52,600
Now we can use this value as a global value,
162

163
00:08:52,600 --> 00:08:54,870
and this value and this value
163

164
00:08:54,870 --> 00:08:56,057
and this value will be the same.
164

165
00:08:56,057 --> 00:08:58,140
they are same value.
165

166
00:08:58,140 --> 00:09:01,310
So, for the global, what I will say here,
166

167
00:09:01,310 --> 00:09:05,650
I need to go to my database and I'll say, person is equal to
167

168
00:09:08,283 --> 00:09:11,827
cur.execute and here what I need to do,
168

169
00:09:11,827 --> 00:09:15,203
I need to here write my SQL code right.
169

170
00:09:17,561 --> 00:09:21,110
select, now I will select from my database.
170

171
00:09:21,110 --> 00:09:24,640
Select star from
171

172
00:09:25,750 --> 00:09:27,880
persons, my table name
172

173
00:09:27,880 --> 00:09:30,343
and after here I will say where,
173

174
00:09:31,410 --> 00:09:36,410
person ID is equal to question mark.
174

175
00:09:39,030 --> 00:09:42,180
But this is not enough, after that what I will say here,
175

176
00:09:42,180 --> 00:09:47,180
comma and here I need to say person ID, okay?
176

177
00:09:47,300 --> 00:09:49,000
Something interesting I need to tell you,
177

178
00:09:49,000 --> 00:09:51,330
after person ID you need to use comma,
178

179
00:09:51,330 --> 00:09:55,010
it's because this is a tuple okay.
179

180
00:09:55,010 --> 00:09:57,060
If you don't use comma here,
180

181
00:09:57,060 --> 00:09:58,920
Python will understand this is a string value,
181

182
00:09:58,920 --> 00:10:01,940
but if you use comma that means this is a tuple.
182

183
00:10:01,940 --> 00:10:05,520
Remember how we can create a single item tuple.
183

184
00:10:05,520 --> 00:10:07,910
It is tuple1, for example.
184

185
00:10:07,910 --> 00:10:12,474
Tuple1 is equal to, if you want to create one item tuple,
185

186
00:10:12,474 --> 00:10:15,720
you need to use again here comma.
186

187
00:10:15,720 --> 00:10:18,160
That's why now we need to use comma,
187

188
00:10:18,160 --> 00:10:21,700
if you don't use you will get error, okay don't forget that.
188

189
00:10:21,700 --> 00:10:24,030
And after that, here what I need to do, I will say,
189

190
00:10:24,030 --> 00:10:25,530
person info
190

191
00:10:27,760 --> 00:10:30,423
is equal to person.fetchall.
191

192
00:10:34,340 --> 00:10:37,880
And here, let's print it out first.
192

193
00:10:37,880 --> 00:10:39,110
Person info
193

194
00:10:41,840 --> 00:10:45,573
and let's go back to here, main and run it.
194

195
00:10:47,210 --> 00:10:50,230
My people, Adam, update.
195

196
00:10:50,230 --> 00:10:52,633
Now, let's check it here, our console.
196

197
00:10:54,830 --> 00:10:57,580
My person info is here so,
197

198
00:10:57,580 --> 00:11:01,020
Python returns me you see, it's ID name, surname
198

199
00:11:01,020 --> 00:11:04,070
and the all other information about my person right?
199

200
00:11:04,070 --> 00:11:08,220
But, this is a you see it here, this is a list.
200

201
00:11:08,220 --> 00:11:10,750
Again, inside this list we have a tuple, right?
201

202
00:11:10,750 --> 00:11:13,960
So, if I want to get these values, what I need here,
202

203
00:11:13,960 --> 00:11:16,300
I need all of them okay by the way.
203

204
00:11:16,300 --> 00:11:20,083
And if I want to, for example, if I want to get ID,
204

205
00:11:21,670 --> 00:11:25,970
here what I need to say, I will say, self.person ID.
205

206
00:11:25,970 --> 00:11:28,530
Okay, they are not same now, this is global person,
206

207
00:11:28,530 --> 00:11:30,063
this is self.person ID.
207

208
00:11:30,910 --> 00:11:34,960
Is equal to I will say, person info.
208

209
00:11:34,960 --> 00:11:39,960
The first will be zero and second one will be again zero.
209

210
00:11:40,840 --> 00:11:44,003
And after that, Control + D again, person.
210

211
00:11:45,000 --> 00:11:46,880
If you want to get this one, for the first one,
211

212
00:11:46,880 --> 00:11:48,830
you need to say, zero zero.
212

213
00:11:48,830 --> 00:11:50,880
For the second one you need to say, zero one.
213

214
00:11:50,880 --> 00:11:54,440
Okay, because this is a list but it has only one item.
214

215
00:11:54,440 --> 00:11:56,613
But inside the list we have another tuple.
215

216
00:11:59,425 --> 00:12:02,700
That's why we need to use here zero zero
216

217
00:12:02,700 --> 00:12:05,500
and zero one for second ID, okay?
217

218
00:12:05,500 --> 00:12:08,330
And for second index actually.
218

219
00:12:08,330 --> 00:12:12,650
So, for that one, what I need to say, I need to say, one.
219

220
00:12:12,650 --> 00:12:14,883
Person name, it will be.
220

221
00:12:15,860 --> 00:12:17,590
And again, Control + D
221

222
00:12:17,590 --> 00:12:21,360
here I will say, person surname,
222

223
00:12:21,360 --> 00:12:24,873
again control + delete, here that one will be email,
223

224
00:12:26,180 --> 00:12:29,923
Control + D phone.
224

225
00:12:31,870 --> 00:12:35,260
And again Control + D, this will be address.
225

226
00:12:35,260 --> 00:12:37,560
Okay, so what I need to change here,
226

227
00:12:37,560 --> 00:12:41,360
this guy will be two, that one will be three,
227

228
00:12:41,360 --> 00:12:44,810
this one will be four and that one will be five.
228

229
00:12:44,810 --> 00:12:49,810
Okay, now we got all information okay, from our database.
229

230
00:12:50,570 --> 00:12:53,210
And which person we selected okay
230

231
00:12:53,210 --> 00:12:55,240
and in this lecture that's all.
231

232
00:12:55,240 --> 00:12:58,370
In previous lecture, sorry in next lesson,
232

233
00:12:58,370 --> 00:13:02,900
we are going to create our design okay?
233

234
00:13:02,900 --> 00:13:07,860
As you remember, our file is, our window is empty.
234

235
00:13:07,860 --> 00:13:10,370
We don't have any design here,
235

236
00:13:10,370 --> 00:13:13,850
update as you see now, is blank, it's totally empty.
236

237
00:13:13,850 --> 00:13:15,960
We will create our design
237

238
00:13:15,960 --> 00:13:20,400
and also we will display our person info at widgets.
238

239
00:13:20,400 --> 00:13:23,420
Our widgets okay, our widgets first one.
239

240
00:13:23,420 --> 00:13:27,993
We have four different entries and also one text widget.
