0
1
00:00:04,930 --> 00:00:05,763
<v Volkan>Hello again.</v>
1

2
00:00:05,763 --> 00:00:07,791
In this lesson, what we are going to do,
2

3
00:00:07,791 --> 00:00:10,070
let me run our application first.
3

4
00:00:10,070 --> 00:00:14,830
Here, we are going to create a function for exit menu item.
4

5
00:00:14,830 --> 00:00:19,120
And this one will little bit more complicated, okay?
5

6
00:00:19,120 --> 00:00:20,360
And here what I need to do,
6

7
00:00:20,360 --> 00:00:25,360
firstly, let's go to create our comment property, okay?
7

8
00:00:25,360 --> 00:00:26,810
It is here, right?
8

9
00:00:26,810 --> 00:00:31,500
And I will say here, comma after enter,
9

10
00:00:31,500 --> 00:00:36,500
comment equals self dot parent dot exitfunc, okay?
10

11
00:00:40,100 --> 00:00:41,560
Something like that.
11

12
00:00:41,560 --> 00:00:42,800
And here what I need to do,
12

13
00:00:42,800 --> 00:00:45,170
I need to create this function, right?
13

14
00:00:45,170 --> 00:00:49,900
And I will go to do find my last function is here.
14

15
00:00:49,900 --> 00:00:51,760
Save as file, right?
15

16
00:00:51,760 --> 00:00:56,760
And here, I will say, def exitfunc, and like before,
16

17
00:00:58,610 --> 00:01:01,270
asterisk arg, arguments, right?
17

18
00:01:01,270 --> 00:01:04,460
And here, what I want to do,
18

19
00:01:04,460 --> 00:01:06,520
here before creating our function,
19

20
00:01:06,520 --> 00:01:09,370
I want to show you something, okay here.
20

21
00:01:09,370 --> 00:01:12,305
I will open again here, Notepad, okay?
21

22
00:01:12,305 --> 00:01:13,520
NotePad.
22

23
00:01:13,520 --> 00:01:14,420
And this here.
23

24
00:01:14,420 --> 00:01:18,050
So we have different options here, okay?
24

25
00:01:18,050 --> 00:01:19,850
Three different options, actually.
25

26
00:01:19,850 --> 00:01:21,460
The first on is, for example, here,
26

27
00:01:21,460 --> 00:01:23,110
this is a new file, right?
27

28
00:01:23,110 --> 00:01:24,870
New file, okay.
28

29
00:01:24,870 --> 00:01:29,870
So if I say file exit, you see I close my application.
29

30
00:01:30,610 --> 00:01:33,743
And for example, if I say notepad now,
30

31
00:01:35,700 --> 00:01:38,340
here because, in previous example,
31

32
00:01:38,340 --> 00:01:41,867
I didn't change content of my file, okay, this important.
32

33
00:01:41,867 --> 00:01:45,600
But if I change my content of file, but now what I need to do,
33

34
00:01:45,600 --> 00:01:47,620
say file exit.
34

35
00:01:47,620 --> 00:01:50,370
Now you see, this guy, this file,
35

36
00:01:50,370 --> 00:01:52,160
it doesn't have a URL, okay?
36

37
00:01:52,160 --> 00:01:56,310
And it says, "Do you want to save changes to Untitled?"
37

38
00:01:56,310 --> 00:01:57,280
For this guy.
38

39
00:01:57,280 --> 00:01:59,320
If I say yes, save,
39

40
00:01:59,320 --> 00:02:02,829
so I will open a new dialogue window here,
40

41
00:02:02,829 --> 00:02:05,010
and after, I will name my file.
41

42
00:02:05,010 --> 00:02:05,980
Okay?
42

43
00:02:05,980 --> 00:02:09,310
And after that, this is second option by the way.
43

44
00:02:09,310 --> 00:02:10,370
If I, for example,
44

45
00:02:10,370 --> 00:02:14,800
if I open an existing file from my computer, that one.
45

46
00:02:14,800 --> 00:02:17,290
Okay, and if I change content of this guy,
46

47
00:02:17,290 --> 00:02:18,853
and if I say exit,
47

48
00:02:19,730 --> 00:02:22,680
and do you want to save changes to this guy,
48

49
00:02:22,680 --> 00:02:26,590
right, this file, if I say yes, save,
49

50
00:02:26,590 --> 00:02:27,423
I will save it,
50

51
00:02:27,423 --> 00:02:30,470
but I will not see a dialogue button here, okay?
51

52
00:02:30,470 --> 00:02:33,560
For example, you see, I save it and quit my application.
52

53
00:02:33,560 --> 00:02:35,170
If I say don't save,
53

54
00:02:35,170 --> 00:02:37,540
I will quit my application and without saving.
54

55
00:02:37,540 --> 00:02:41,390
If I say cancel, that means I will not do anything, okay?
55

56
00:02:41,390 --> 00:02:44,419
So, here, what I need to do,
56

57
00:02:44,419 --> 00:02:49,419
also I need to know that my content of file,
57

58
00:02:49,450 --> 00:02:54,450
change or, I change my content or I didn't change, okay?
58

59
00:02:55,710 --> 00:02:57,220
This is very important.
59

60
00:02:57,220 --> 00:02:58,800
And here, what I need to do,
60

61
00:02:58,800 --> 00:03:02,540
I need to create here global variable first, URL.
61

62
00:03:03,520 --> 00:03:05,280
And also, remember,
62

63
00:03:05,280 --> 00:03:08,720
we already created text changed global variable.
63

64
00:03:08,720 --> 00:03:09,960
It's here, right?
64

65
00:03:09,960 --> 00:03:12,080
Text changed false.
65

66
00:03:12,080 --> 00:03:14,510
For default, by default, it is false.
66

67
00:03:14,510 --> 00:03:19,510
So here, and I need to use here also text changed.
67

68
00:03:20,600 --> 00:03:21,790
Okay, this is important.
68

69
00:03:21,790 --> 00:03:24,020
If changed, we are doing something else.
69

70
00:03:24,020 --> 00:03:27,192
If we are not changed, we'll do something else.
70

71
00:03:27,192 --> 00:03:28,400
Okay, this is important.
71

72
00:03:28,400 --> 00:03:33,400
So, here, between  try and except, I would say except.
72

73
00:03:33,630 --> 00:03:36,930
For except we can say return, okay, simply.
73

74
00:03:36,930 --> 00:03:39,830
But for try, we need to do something more.
74

75
00:03:39,830 --> 00:03:41,330
And here, first I will say,
75

76
00:03:41,330 --> 00:03:46,330
if text changed equals equals true, okay,
76

77
00:03:46,590 --> 00:03:49,130
that means I changed my content.
77

78
00:03:49,130 --> 00:03:52,550
So here, I need to use message box, okay?
78

79
00:03:52,550 --> 00:03:56,333
And I will say mbox equals message box.
79

80
00:03:59,230 --> 00:04:02,240
So what I need to do, I need to import message box, okay,
80

81
00:04:02,240 --> 00:04:05,560
from tkinter import here.
81

82
00:04:05,560 --> 00:04:10,560
Message box, and now I can use message box here.
82

83
00:04:11,240 --> 00:04:13,260
Let's find it, it's here.
83

84
00:04:13,260 --> 00:04:14,750
So I will say,
84

85
00:04:14,750 --> 00:04:19,750
message box dot yes no cancel, okay, that one.
85

86
00:04:20,760 --> 00:04:23,330
And after here, the first parameter
86

87
00:04:23,330 --> 00:04:26,670
will be my title, Warning, okay.
87

88
00:04:26,670 --> 00:04:31,504
Second ones is my message, and I will say,
88

89
00:04:31,504 --> 00:04:36,504
do you want to save the file, okay?
89

90
00:04:38,410 --> 00:04:39,980
And this is enough.
90

91
00:04:39,980 --> 00:04:43,460
After that what I need to do, here I need to check,
91

92
00:04:43,460 --> 00:04:48,380
because here for yes no cancel and message box,
92

93
00:04:48,380 --> 00:04:50,220
we have three options, okay?
93

94
00:04:50,220 --> 00:04:55,143
So I need to tell you something for if user says yes,
94

95
00:04:56,690 --> 00:05:00,370
that means this guy will return me true.
95

96
00:05:00,370 --> 00:05:03,780
If no, for the the no button, it will return me false,
96

97
00:05:03,780 --> 00:05:06,110
or cancel it will return me none.
97

98
00:05:06,110 --> 00:05:06,943
Okay?
98

99
00:05:06,943 --> 00:05:08,470
So here, what I need to do,
99

100
00:05:08,470 --> 00:05:13,450
I will say if mbox is true,
100

101
00:05:14,830 --> 00:05:19,140
okay that means you user clicked yes button, okay?
101

102
00:05:19,140 --> 00:05:20,305
Do you want to save file?
102

103
00:05:20,305 --> 00:05:21,319
Yes.
103

104
00:05:21,319 --> 00:05:23,220
So, now what I need to do,
104

105
00:05:23,220 --> 00:05:25,890
I need to check something else again, okay?
105

106
00:05:25,890 --> 00:05:29,010
Now, I need to, know if this guy
106

107
00:05:29,010 --> 00:05:31,850
is an existing file or a new file.
107

108
00:05:31,850 --> 00:05:36,850
So, like we did for save, right, over here, save.
108

109
00:05:38,510 --> 00:05:39,343
Save file.
109

110
00:05:39,343 --> 00:05:40,760
So we will do same thing, okay?
110

111
00:05:40,760 --> 00:05:45,760
Here, I will say, if URL not equals empty, okay.
111

112
00:05:50,470 --> 00:05:51,350
And here I will say
112

113
00:05:51,350 --> 00:05:56,350
content equals self dot text editor dot get
113

114
00:05:59,450 --> 00:06:04,450
from first until end, right?
114

115
00:06:04,590 --> 00:06:06,660
And here, what I need to do, like before,
115

116
00:06:06,660 --> 00:06:11,650
I say with open and I will use here URL
116

117
00:06:13,320 --> 00:06:17,516
and second one will be write mode , right?
117

118
00:06:17,516 --> 00:06:22,516
And encoding equals "utf-8", okay?
118

119
00:06:25,720 --> 00:06:28,713
And here I will say as file.
119

120
00:06:29,970 --> 00:06:34,970
And here I will say file dot write and my content, okay?
120

121
00:06:39,000 --> 00:06:40,520
And after that, what I need to do,
121

122
00:06:40,520 --> 00:06:42,320
now I need to destroy my window,
122

123
00:06:42,320 --> 00:06:45,290
because I already saved my file, okay?
123

124
00:06:45,290 --> 00:06:49,480
And I will destroy my file, sorry I will destroy my window.
124

125
00:06:49,480 --> 00:06:54,480
Self dot parent dot destroy, okay?
125

126
00:06:59,010 --> 00:07:03,113
Now, even we can't see that here, for example, notepad, here.
126

127
00:07:05,540 --> 00:07:10,270
Let's open an existing file, because it has a URL, right?
127

128
00:07:10,270 --> 00:07:14,730
And now open, that one, right?
128

129
00:07:14,730 --> 00:07:16,663
Now, I will change something.
129

130
00:07:17,610 --> 00:07:19,020
File exit.
130

131
00:07:19,020 --> 00:07:20,713
Do you want to save your file?
131

132
00:07:20,713 --> 00:07:22,660
This said here what we said.
132

133
00:07:22,660 --> 00:07:24,580
We said yes, right?
133

134
00:07:24,580 --> 00:07:28,403
Mbox is true, save, you see?
134

135
00:07:29,310 --> 00:07:31,670
We destroyed our window, okay?
135

136
00:07:31,670 --> 00:07:32,663
And for else,
136

137
00:07:34,260 --> 00:07:39,260
now else means here, my URL is not,
137

138
00:07:40,630 --> 00:07:44,070
sorry my, not exist, okay?
138

139
00:07:44,070 --> 00:07:46,270
So let me set this to new file.
139

140
00:07:46,270 --> 00:07:48,680
And here I will create another content variable.
140

141
00:07:48,680 --> 00:07:51,713
Content2 equals str, okay?
141

142
00:07:52,680 --> 00:07:55,590
And I will say self dot text editor get
142

143
00:07:59,700 --> 00:08:02,430
from first until end, right?
143

144
00:08:02,430 --> 00:08:05,860
And now what I need to do, I need to use here,
144

145
00:08:05,860 --> 00:08:07,230
dialog window, okay?
145

146
00:08:07,230 --> 00:08:09,710
So, I'll say URL equals,
146

147
00:08:09,710 --> 00:08:12,393
because this guy doesn't have a URL, okay?
147

148
00:08:13,289 --> 00:08:17,120
URL is not empty, that one, that means URL is empty.
148

149
00:08:17,120 --> 00:08:18,733
So file dialogue.
149

150
00:08:19,910 --> 00:08:23,563
Even for this guy, let's copy this one, okay?
150

151
00:08:24,840 --> 00:08:26,453
And paste it here.
151

152
00:08:30,410 --> 00:08:34,416
And after that, what I need to do, like before, I will say
152

153
00:08:34,416 --> 00:08:39,416
URL dot write, and I will say here content two.
153

154
00:08:40,920 --> 00:08:42,430
Now I can close my URL.
154

155
00:08:42,430 --> 00:08:45,780
URL dot close, okay?
155

156
00:08:45,780 --> 00:08:49,093
And now this is second option.
156

157
00:08:50,940 --> 00:08:52,830
Sorry, this is first option, right?
157

158
00:08:52,830 --> 00:08:57,830
This is for if, if mbox, I will come here
158

159
00:08:57,890 --> 00:09:00,490
if mbox is false, is false
159

160
00:09:06,717 --> 00:09:10,980
that means user said "no," okay?
160

161
00:09:10,980 --> 00:09:13,620
What I will do here, I will say,
161

162
00:09:13,620 --> 00:09:18,620
self dot parent dot destroy, okay?
162

163
00:09:18,630 --> 00:09:23,140
Because this asks the user, do you want to save file?
163

164
00:09:23,140 --> 00:09:25,400
He said or she said, "No."
164

165
00:09:25,400 --> 00:09:27,360
So we will destroy our window, okay?
165

166
00:09:27,360 --> 00:09:31,183
And for the last one, last one means here,
166

167
00:09:35,480 --> 00:09:39,310
sorry, here, mbox is true, yes is that one.
167

168
00:09:39,310 --> 00:09:44,310
And for mbox is false, we say no, and for last option,
168

169
00:09:45,270 --> 00:09:48,140
here what we we know here, if text changed, right?
169

170
00:09:48,140 --> 00:09:50,830
This is is for true, for if text,
170

171
00:09:50,830 --> 00:09:53,810
if we didn't change our text content,
171

172
00:09:53,810 --> 00:09:55,640
that means here I will say
172

173
00:09:55,640 --> 00:10:00,553
else self dot parent dot destroy again, okay?
173

174
00:10:02,160 --> 00:10:03,440
By the way, for cancel,
174

175
00:10:03,440 --> 00:10:06,320
you might wonder why we don't use for cancel,
175

176
00:10:06,320 --> 00:10:11,320
because, let me, here for example, notepad, okay?
176

177
00:10:11,370 --> 00:10:13,440
And I will change content.
177

178
00:10:13,440 --> 00:10:15,450
I will say file exit.
178

179
00:10:15,450 --> 00:10:18,360
If I say cancel, you see nothing happens,
179

180
00:10:18,360 --> 00:10:21,083
so we don't need to do something for cancel.
180

181
00:10:21,083 --> 00:10:22,810
Even we can open a new file.
181

182
00:10:22,810 --> 00:10:25,410
Let's delete this one.
182

183
00:10:25,410 --> 00:10:26,423
And open.
183

184
00:10:27,640 --> 00:10:31,330
And here, I will change the content, okay?
184

185
00:10:31,330 --> 00:10:34,170
And say exit, cancel.
185

186
00:10:34,170 --> 00:10:35,320
You see nothing happens,
186

187
00:10:35,320 --> 00:10:39,390
so we don't need to do something for cancel button, okay?
187

188
00:10:39,390 --> 00:10:40,940
And don't save.
188

189
00:10:40,940 --> 00:10:45,200
So, and for if text changed true, we are going to do that.
189

190
00:10:45,200 --> 00:10:48,000
If we didn't change text, that means here,
190

191
00:10:48,000 --> 00:10:52,283
by the way, let me show you, to, here notepad again.
191

192
00:10:54,210 --> 00:10:58,266
And here, this guy doesn't have URL.
192

193
00:10:58,266 --> 00:11:01,120
If I say exit, you see nothing happens.
193

194
00:11:01,120 --> 00:11:02,437
I destroy my window.
194

195
00:11:02,437 --> 00:11:06,520
Even if I open an existing file from my computer,
195

196
00:11:08,264 --> 00:11:10,847
file open, let's open that one.
196

197
00:11:12,089 --> 00:11:16,706
Now, I don't change my content and say file exit.
197

198
00:11:16,706 --> 00:11:18,295
You see, I destroy my window.
198

199
00:11:18,295 --> 00:11:22,091
And this else will be executed, okay?
199

200
00:11:22,091 --> 00:11:25,279
And now if I run our application,
200

201
00:11:25,279 --> 00:11:27,179
we will see what happens.
201

202
00:11:27,179 --> 00:11:30,539
Now here, for example, that one,
202

203
00:11:30,539 --> 00:11:32,364
already the text changed, right?
203

204
00:11:32,364 --> 00:11:35,511
And if I say exit, do you want to save the file?
204

205
00:11:35,511 --> 00:11:36,572
I will say cancel.
205

206
00:11:36,572 --> 00:11:38,273
Nothing happens.
206

207
00:11:38,273 --> 00:11:42,076
If I say exit again, no, we destroy our window.
207

208
00:11:42,076 --> 00:11:43,659
Let's run it again.
208

209
00:11:44,572 --> 00:11:48,274
And here I will say, this a new file, by the way.
209

210
00:11:48,274 --> 00:11:49,278
Exit.
210

211
00:11:49,278 --> 00:11:50,656
Do you want to save the file?
211

212
00:11:50,656 --> 00:11:51,492
Yes.
212

213
00:11:51,492 --> 00:11:56,082
So you see, this is this dialog window we opened,
213

214
00:11:56,082 --> 00:11:57,760
because this guy doesn't have URL.
214

215
00:11:57,760 --> 00:12:00,090
So cancel, okay?
215

216
00:12:00,090 --> 00:12:03,263
And now, here I will delete this one,
216

217
00:12:04,360 --> 00:12:06,810
and say open an existing one.
217

218
00:12:06,810 --> 00:12:07,833
This one, okay.
218

219
00:12:09,030 --> 00:12:13,430
And here, if I click exit, do you want to save the file?
219

220
00:12:13,430 --> 00:12:14,263
Yes.
220

221
00:12:14,263 --> 00:12:16,050
And after that, I destroy my window.
221

222
00:12:16,050 --> 00:12:19,530
This is how we can create exit function for our application.
222

223
00:12:19,530 --> 00:12:20,620
For now, that's all.
223

224
00:12:20,620 --> 00:12:21,620
See you in the next.
