0
1
00:00:04,820 --> 00:00:06,320
<v ->Hello again Python Tkinker</v>
1

2
00:00:06,320 --> 00:00:08,155
In previous lecture what we did, we created our design for our
2

3
00:00:08,155 --> 00:00:10,840
add book window right
3

4
00:00:10,840 --> 00:00:12,270
and it's here
4

5
00:00:12,270 --> 00:00:14,830
so what we need to do know, when I hit
5

6
00:00:14,830 --> 00:00:16,170
this button
6

7
00:00:16,170 --> 00:00:19,402
I need to enter all values from my
7

8
00:00:19,402 --> 00:00:21,510
entries to database right
8

9
00:00:21,510 --> 00:00:23,520
I need to enter a book
9

10
00:00:25,597 --> 00:00:27,190
when I click, when I hit this my button
10

11
00:00:27,190 --> 00:00:30,050
To do that what I need to do here I will go make
11

12
00:00:30,050 --> 00:00:31,460
here pass
12

13
00:00:31,460 --> 00:00:33,130
I said remember
13

14
00:00:33,130 --> 00:00:36,040
I need to get values from my entries
14

15
00:00:36,040 --> 00:00:38,073
right for the name I will  say self.
15

16
00:00:38,073 --> 00:00:39,813
Name is equals to self.
16

17
00:00:40,950 --> 00:00:44,410
Entry name. get value okay
17

18
00:00:44,410 --> 00:00:47,317
and after that for author
18

19
00:00:47,317 --> 00:00:49,210
author is same
19

20
00:00:49,210 --> 00:00:50,730
self. entry
20

21
00:00:53,616 --> 00:00:55,060
author. get right
21

22
00:00:56,418 --> 00:00:57,251
for page
22

23
00:00:58,843 --> 00:01:01,320
I will say self. entry
23

24
00:01:01,320 --> 00:01:02,950
page. get
24

25
00:01:06,090 --> 00:01:07,485
and
25

26
00:01:07,485 --> 00:01:10,390
for language I will say self
26

27
00:01:10,390 --> 00:01:11,590
entry
27

28
00:01:11,590 --> 00:01:13,520
language. get
28

29
00:01:14,720 --> 00:01:15,630
okay
29

30
00:01:15,630 --> 00:01:17,150
so what I need to do now
30

31
00:01:17,150 --> 00:01:19,760
I need to here check this values
31

32
00:01:19,760 --> 00:01:22,090
if they are empty or not okay
32

33
00:01:22,090 --> 00:01:23,630
and here I will say if
33

34
00:01:25,560 --> 00:01:26,393
name
34

35
00:01:28,730 --> 00:01:31,016
name and
35

36
00:01:31,016 --> 00:01:32,670
author
36

37
00:01:32,670 --> 00:01:33,800
and
37

38
00:01:33,800 --> 00:01:35,800
I cannot use here or
38

39
00:01:35,800 --> 00:01:38,070
because I am checking all of them okay
39

40
00:01:38,070 --> 00:01:41,823
so that's why I need to use here and page and
40

41
00:01:41,823 --> 00:01:43,840
language
41

42
00:01:43,840 --> 00:01:45,270
not equals
42

43
00:01:47,250 --> 00:01:48,083
none.
43

44
00:01:48,083 --> 00:01:52,140
okay if they are not none, not empty or anyway
44

45
00:01:52,140 --> 00:01:54,680
so I will say try
45

46
00:01:54,680 --> 00:01:55,513
that means
46

47
00:01:56,528 --> 00:01:57,810
an after that for try
47

48
00:01:57,810 --> 00:02:00,361
and also lets say except
48

49
00:02:00,361 --> 00:02:01,194
for except for now
49

50
00:02:01,194 --> 00:02:02,360
I'II say pass
50

51
00:02:02,360 --> 00:02:03,420
okay
51

52
00:02:03,420 --> 00:02:04,360
if try
52

53
00:02:05,300 --> 00:02:06,340
for try block
53

54
00:02:06,340 --> 00:02:09,230
I will say, what I will say
54

55
00:02:09,230 --> 00:02:11,270
I will need to create here a query
55

56
00:02:11,270 --> 00:02:13,150
and my query will be
56

57
00:02:16,440 --> 00:02:18,070
here
57

58
00:02:18,070 --> 00:02:19,040
insert
58

59
00:02:19,040 --> 00:02:20,270
sorry
59

60
00:02:20,270 --> 00:02:21,180
quotes
60

61
00:02:21,180 --> 00:02:23,050
insert into
61

62
00:02:24,841 --> 00:02:26,470
my table name was books right
62

63
00:02:27,403 --> 00:02:29,700
so single quotes okay
63

64
00:02:29,700 --> 00:02:34,640
and here I need to say books right
64

65
00:02:34,640 --> 00:02:36,700
and after single quotes what I need to say
65

66
00:02:36,700 --> 00:02:40,530
I need to use here parentheses okay for my
66

67
00:02:40,530 --> 00:02:41,820
tables okay
67

68
00:02:41,820 --> 00:02:46,470
and I will say here book underscore name okay
68

69
00:02:46,470 --> 00:02:49,670
and other one is book author
69

70
00:02:49,670 --> 00:02:51,595
my fields these ok
70

71
00:02:51,595 --> 00:02:52,995
book author
71

72
00:02:54,290 --> 00:02:56,780
and other one is book page
72

73
00:02:58,246 --> 00:02:59,079
and book page
73

74
00:03:01,950 --> 00:03:03,880
and last one was
74

75
00:03:06,240 --> 00:03:08,160
book language
75

76
00:03:08,160 --> 00:03:12,250
I think and book underscore language okay
76

77
00:03:12,250 --> 00:03:14,150
so after what I need to do now
77

78
00:03:14,150 --> 00:03:17,450
I need to here say values okay
78

79
00:03:17,450 --> 00:03:18,300
after parentheses
79

80
00:03:20,060 --> 00:03:22,110
close parentheses, I need to say here values
80

81
00:03:23,026 --> 00:03:25,269
and instead of values what I need to use here
81

82
00:03:25,269 --> 00:03:26,760
I need to use question marks okay
82

83
00:03:26,760 --> 00:03:28,043
how many values I have?
83

84
00:03:28,890 --> 00:03:31,450
One two three and four right
84

85
00:03:31,450 --> 00:03:34,760
so that means I need to use three different
85

86
00:03:35,895 --> 00:03:39,530
question marks for one two three
86

87
00:03:39,530 --> 00:03:40,615
and
87

88
00:03:40,615 --> 00:03:42,000
this is last one four, okay
88

89
00:03:43,011 --> 00:03:44,111
and now what I need to do
89

90
00:03:45,220 --> 00:03:47,060
I need to come here and say
90

91
00:03:50,045 --> 00:03:50,878
my cursor object
91

92
00:03:50,878 --> 00:03:51,711
cur.
92

93
00:03:51,711 --> 00:03:53,255
cur. execute
93

94
00:03:53,255 --> 00:03:55,090
but I cannot use my cursor object why is like that?
94

95
00:03:55,090 --> 00:03:56,930
because here what I need to do
95

96
00:03:56,930 --> 00:04:00,200
I need to say here con is equal to
96

97
00:04:02,450 --> 00:04:04,124
connection. right
97

98
00:04:04,124 --> 00:04:04,957
I need to say
98

99
00:04:05,970 --> 00:04:07,410
sqlite3 connect
99

100
00:04:08,616 --> 00:04:11,210
sqlite3. Connect right
100

101
00:04:11,210 --> 00:04:14,490
and after that my database name it is
101

102
00:04:14,490 --> 00:04:16,010
library. db right
102

103
00:04:16,010 --> 00:04:16,843
its here
103

104
00:04:18,676 --> 00:04:20,350
library. db
104

105
00:04:21,497 --> 00:04:24,039
and also I need to create my cursor object
105

106
00:04:24,039 --> 00:04:25,940
cursor is equal to
106

107
00:04:25,940 --> 00:04:28,010
connection object. cursor okay
107

108
00:04:29,600 --> 00:04:31,267
and after that what I need to do
108

109
00:04:31,267 --> 00:04:34,010
I'm going to come back here
109

110
00:04:34,010 --> 00:04:36,190
and I will say
110

111
00:04:36,190 --> 00:04:38,620
cursor. execute
111

112
00:04:38,620 --> 00:04:41,209
I will execute my query first
112

113
00:04:41,209 --> 00:04:42,376
and after that here
113

114
00:04:44,295 --> 00:04:46,902
parentheses and my values okay
114

115
00:04:46,902 --> 00:04:47,735
name
115

116
00:04:49,255 --> 00:04:50,088
and author
116

117
00:04:53,400 --> 00:04:55,080
page and language right
117

118
00:04:55,080 --> 00:04:57,089
page and
118

119
00:04:57,089 --> 00:04:58,120
language
119

120
00:05:00,240 --> 00:05:01,633
that's all
120

121
00:05:01,633 --> 00:05:03,125
so what I'm doing here
121

122
00:05:03,125 --> 00:05:04,218
now this for
122

123
00:05:04,218 --> 00:05:06,470
instead of this values I will use
123

124
00:05:06,470 --> 00:05:08,520
name, author page and language okay
124

125
00:05:08,520 --> 00:05:09,620
for this question marks
125

126
00:05:11,340 --> 00:05:13,770
and after that what I need to say con. commit
126

127
00:05:15,330 --> 00:05:18,260
and if everything is fine I want to show
127

128
00:05:18,260 --> 00:05:20,097
a message box
128

129
00:05:20,097 --> 00:05:23,920
messagebox.show info and first one will
129

130
00:05:23,920 --> 00:05:26,290
be my title success
130

131
00:05:26,290 --> 00:05:30,644
second one will be my message success-
131

132
00:05:30,644 --> 00:05:32,740
<v ->fully</v>
132

133
00:05:32,740 --> 00:05:34,940
added to data-
133

134
00:05:34,940 --> 00:05:36,220
<v ->base</v>
134

135
00:05:36,220 --> 00:05:37,540
and
135

136
00:05:37,540 --> 00:05:39,040
if you want you can also
136

137
00:05:40,939 --> 00:05:42,340
you say icon here
137

138
00:05:42,340 --> 00:05:43,690
info icon
138

139
00:05:43,690 --> 00:05:44,523
okay
139

140
00:05:44,523 --> 00:05:45,570
and if not
140

141
00:05:47,360 --> 00:05:49,760
everything if, if you have any problem
141

142
00:05:49,760 --> 00:05:51,930
again a message box but this time
142

143
00:05:51,930 --> 00:05:54,720
show error okay
143

144
00:05:54,720 --> 00:05:55,670
and
144

145
00:05:55,670 --> 00:05:59,450
here I will say error for title of my end of
145

146
00:05:59,450 --> 00:06:01,400
message box or anyway or
146

147
00:06:01,400 --> 00:06:04,060
and here my message will be can't
147

148
00:06:05,150 --> 00:06:07,440
add to database
148

149
00:06:07,440 --> 00:06:10,424
and icon, this is optional by the way
149

150
00:06:10,424 --> 00:06:11,370
icon don't forget that
150

151
00:06:11,370 --> 00:06:13,990
here we don't need to use icon and
151

152
00:06:13,990 --> 00:06:16,310
I want to say here warning okay
152

153
00:06:17,980 --> 00:06:19,680
and this is also fine
153

154
00:06:19,680 --> 00:06:21,660
but this is for if right
154

155
00:06:21,660 --> 00:06:25,340
also I meed to create else statement here
155

156
00:06:25,340 --> 00:06:26,430
and something wrong here
156

157
00:06:26,430 --> 00:06:27,950
let me check because
157

158
00:06:27,950 --> 00:06:29,510
icon must be here
158

159
00:06:29,510 --> 00:06:30,810
so delete this guy
159

160
00:06:32,990 --> 00:06:33,823
and here
160

161
00:06:34,778 --> 00:06:35,611
sorry
161

162
00:06:36,930 --> 00:06:38,210
lets delete all of them
162

163
00:06:40,370 --> 00:06:41,550
here like that right
163

164
00:06:41,550 --> 00:06:44,870
and after that here what I need to say comma
164

165
00:06:44,870 --> 00:06:48,010
icon and icon is going to be
165

166
00:06:48,850 --> 00:06:50,830
warning okay
166

167
00:06:50,830 --> 00:06:51,720
now its fine
167

168
00:06:55,288 --> 00:06:56,888
and must be something wrong
168

169
00:06:58,650 --> 00:07:00,530
here, another
169

170
00:07:02,210 --> 00:07:05,045
if we don't need to use another parentheses
170

171
00:07:05,045 --> 00:07:05,878
but here
171

172
00:07:05,878 --> 00:07:07,990
so I need to remove one of them, this one
172

173
00:07:09,608 --> 00:07:10,441
it is fine now
173

174
00:07:11,570 --> 00:07:13,020
yes, its fine now
174

175
00:07:13,020 --> 00:07:14,880
and what I need to do
175

176
00:07:14,880 --> 00:07:16,840
I need to create my else statement
176

177
00:07:18,004 --> 00:07:18,837
else
177

178
00:07:18,837 --> 00:07:20,660
I need to use another message box okay
178

179
00:07:20,660 --> 00:07:22,620
and it will be that one
179

180
00:07:22,620 --> 00:07:24,550
but my message will be different
180

181
00:07:24,550 --> 00:07:25,820
so I will say here
181

182
00:07:27,970 --> 00:07:29,570
error fields
182

183
00:07:31,230 --> 00:07:32,670
fields can't
183

184
00:07:33,780 --> 00:07:34,613
be empty
184

185
00:07:35,740 --> 00:07:37,560
what I'm doing here, let me check
185

186
00:07:37,560 --> 00:07:38,810
so I say here
186

187
00:07:38,810 --> 00:07:40,400
if my fields all of them 
187

188
00:07:41,860 --> 00:07:43,430
I check my fields right
188

189
00:07:43,430 --> 00:07:45,350
if there is no empty one
189

190
00:07:45,350 --> 00:07:48,420
then I will go to the here try okay
190

191
00:07:48,420 --> 00:07:50,130
and if I try successful
191

192
00:07:50,130 --> 00:07:51,768
I will show this message
192

193
00:07:51,768 --> 00:07:53,210
and if not something wrong about my database,
193

194
00:07:53,210 --> 00:07:55,910
my query, my system anything okay
194

195
00:07:55,910 --> 00:07:57,830
can be happen so I will say here
195

196
00:07:57,830 --> 00:07:59,400
something wrong about your
196

197
00:08:00,250 --> 00:08:02,170
and you cannot add to database okay
197

198
00:08:02,170 --> 00:08:05,390
and if not, for example if one of them is not
198

199
00:08:05,390 --> 00:08:06,720
if null
199

200
00:08:06,720 --> 00:08:10,050
if, one of these values 
200

201
00:08:10,050 --> 00:08:11,500
null okay
201

202
00:08:11,500 --> 00:08:13,290
we will use else statement
202

203
00:08:13,290 --> 00:08:15,510
for this one, everything is fine
203

204
00:08:15,510 --> 00:08:16,830
here all the fields is fine
204

205
00:08:16,830 --> 00:08:18,900
so we will execute this block
205

206
00:08:18,900 --> 00:08:20,470
if not, we will say so
206

207
00:08:20,470 --> 00:08:23,110
this, one of your fields is empty or
207

208
00:08:23,110 --> 00:08:24,380
more than one okay
208

209
00:08:24,380 --> 00:08:26,207
and here what I need to do
209

210
00:08:26,207 --> 00:08:29,690
I need to run my application only now
210

211
00:08:29,690 --> 00:08:30,740
I will say run
211

212
00:08:32,470 --> 00:08:34,700
add book and this is our first book
212

213
00:08:36,497 --> 00:08:37,330
so I will say here
213

214
00:08:37,330 --> 00:08:39,760
crime and punishment
214

215
00:08:41,060 --> 00:08:41,893
okay
215

216
00:08:43,938 --> 00:08:44,771
and Fyodor
216

217
00:08:46,993 --> 00:08:47,826
Dostoevsky
217

218
00:08:49,930 --> 00:08:50,763
and page is
218

219
00:08:50,763 --> 00:08:52,020
I think 965
219

220
00:08:52,020 --> 00:08:53,662
something like that
220

221
00:08:53,662 --> 00:08:55,862
it was really nice and great book by the way
221

222
00:08:57,127 --> 00:08:58,960
and language is Russian okay
222

223
00:08:58,960 --> 00:08:59,920
add book
223

224
00:08:59,920 --> 00:09:01,920
successfully added to database
224

225
00:09:01,920 --> 00:09:04,370
everything works very very fine
225

226
00:09:04,370 --> 00:09:07,150
even let's go back to our library. db
226

227
00:09:07,150 --> 00:09:08,160
show in explorer
227

228
00:09:10,900 --> 00:09:11,733
library
228

229
00:09:15,530 --> 00:09:16,760
and books right
229

230
00:09:17,718 --> 00:09:20,420
so I need to say here browse data
230

231
00:09:20,420 --> 00:09:21,890
and here as you see now
231

232
00:09:21,890 --> 00:09:24,440
our books is here
232

233
00:09:24,440 --> 00:09:26,860
crime and punishment okay
233

234
00:09:26,860 --> 00:09:29,003
for now that's all, see you in the next.
