0
1
00:00:04,841 --> 00:00:05,674
<v Volkan>Hello, again.</v>
1

2
00:00:05,674 --> 00:00:07,712
In previous lecture what we did, we created
2

3
00:00:07,712 --> 00:00:10,510
our newFile menu item
3

4
00:00:10,510 --> 00:00:13,570
sorry, we created our function for new menu item, right.
4

5
00:00:13,570 --> 00:00:15,750
And in this session, what we are going to do
5

6
00:00:15,750 --> 00:00:18,460
let me go back to our menu
6

7
00:00:18,460 --> 00:00:19,640
menu is here, right.
7

8
00:00:19,640 --> 00:00:22,180
We are going to create our function
8

9
00:00:22,180 --> 00:00:25,044
for this open menu item, okay.
9

10
00:00:25,044 --> 00:00:27,130
Here, what I will do,
10

11
00:00:27,130 --> 00:00:29,647
let's use comma and after that hit Enter, okay
11

12
00:00:29,647 --> 00:00:33,290
and I will say command equals
12

13
00:00:33,290 --> 00:00:35,980
self.parent.openFile
13

14
00:00:40,730 --> 00:00:41,563
Okay
14

15
00:00:42,560 --> 00:00:44,132
and now, what I need to do?
15

16
00:00:44,132 --> 00:00:47,770
I need to create this openFile function, right.
16

17
00:00:47,770 --> 00:00:48,880
Here I will come
17

18
00:00:51,470 --> 00:00:55,330
and here before newFile
18

19
00:00:55,330 --> 00:00:56,970
and I will say
19

20
00:00:56,970 --> 00:00:59,390
def openFile here
20

21
00:00:59,390 --> 00:01:00,670
what I need to use?
21

22
00:01:00,670 --> 00:01:03,983
I need to use also args, right, asterisk args.
22

23
00:01:04,930 --> 00:01:07,150
Okay and now here, what I need to do?
23

24
00:01:07,150 --> 00:01:11,470
I need to call my global URL variable, okay.
24

25
00:01:11,470 --> 00:01:12,540
And here what I will say?
25

26
00:01:12,540 --> 00:01:15,780
I will say URL equals now.
26

27
00:01:15,780 --> 00:01:18,090
What I need to do? I'm to use file dialogue, okay
27

28
00:01:18,090 --> 00:01:21,020
we already learned how we can use file dialogue, by the way.
28

29
00:01:21,020 --> 00:01:22,490
Here, I will say
29

30
00:01:26,610 --> 00:01:29,423
file dialogue and what I need to?
30

31
00:01:29,423 --> 00:01:32,890
I need to import my file dialogue, by the way
31

32
00:01:32,890 --> 00:01:35,510
and here what I need to do? I will go to the top
32

33
00:01:35,510 --> 00:01:37,200
and say
33

34
00:01:37,200 --> 00:01:40,256
from tkinter import filedialog
34

35
00:01:40,256 --> 00:01:41,900
okay
35

36
00:01:41,900 --> 00:01:44,183
and now I can use filedialog.
36

37
00:01:46,532 --> 00:01:48,375
Yes.
37

38
00:01:48,375 --> 00:01:51,483
URL equals I will say filedialog.askopenfilename
38

39
00:01:55,470 --> 00:02:00,000
okay, that one askopenfilename
39

40
00:02:00,000 --> 00:02:01,803
and after that here what I need to use?
40

41
00:02:04,780 --> 00:02:08,960
askopenfilename and here I will say initial directory
41

42
00:02:11,260 --> 00:02:13,740
okay, here it will be
42

43
00:02:16,110 --> 00:02:18,100
my current directory, okay
43

44
00:02:18,100 --> 00:02:21,170
and after that here I want to use title for my
44

45
00:02:23,520 --> 00:02:26,180
dialog window. okay, title will be
45

46
00:02:27,050 --> 00:02:31,360
Select a file to open
46

47
00:02:31,360 --> 00:02:34,200
something like that and also which property I will use?
47

48
00:02:34,200 --> 00:02:37,400
I will use also file types property, okay
48

49
00:02:37,400 --> 00:02:39,387
for the file types what I will say here
49

50
00:02:42,296 --> 00:02:46,525
file types, even, we can come here, okay and say
50

51
00:02:46,525 --> 00:02:47,358
filetypes
51

52
00:02:50,340 --> 00:02:51,173
equals
52

53
00:02:52,920 --> 00:02:55,990
parentheses and another parentheses here I will say
53

54
00:02:58,310 --> 00:03:01,900
Text file, okay, first of all,
54

55
00:03:01,900 --> 00:03:04,810
and after that here I will use comma
55

56
00:03:04,810 --> 00:03:08,440
and now I need to use extension for text files, okay
56

57
00:03:08,440 --> 00:03:13,070
and I will say star .txt, right
57

58
00:03:13,070 --> 00:03:16,470
and after what I need do also, I need to use another property
58

59
00:03:16,470 --> 00:03:17,630
and I will say here
59

60
00:03:19,480 --> 00:03:22,283
for this one I will say All Files, okay.
60

61
00:03:23,350 --> 00:03:26,880
And here I will say All Files
61

62
00:03:28,410 --> 00:03:30,780
and again here comma
62

63
00:03:32,150 --> 00:03:35,500
and asterisk
63

64
00:03:35,500 --> 00:03:36,887
quotes
64

65
00:03:36,887 --> 00:03:37,720
*.*
65

66
00:03:39,070 --> 00:03:42,470
Okay, I think it's fine now.
66

67
00:03:42,470 --> 00:03:43,670
Let me check it.
67

68
00:03:43,670 --> 00:03:46,923
Looks fine, okay, and here what I need to do now?
68

69
00:03:47,810 --> 00:03:50,630
Now we can use this URL variable
69

70
00:03:50,630 --> 00:03:52,788
to open up our text file, okay.
70

71
00:03:52,788 --> 00:03:54,840
What I need to do? I will use
71

72
00:03:54,840 --> 00:03:58,140
here try and except blocks, okay,
72

73
00:03:58,140 --> 00:03:59,680
and here I will say try
73

74
00:04:01,750 --> 00:04:03,923
and also, let's say except, okay.
74

75
00:04:08,730 --> 00:04:11,427
For now, let's say pass and here what I will say?
75

76
00:04:11,427 --> 00:04:16,230
I will use with open, right
76

77
00:04:16,230 --> 00:04:19,200
and I will open URL, right
77

78
00:04:19,200 --> 00:04:20,200
and what I need to do?
78

79
00:04:20,200 --> 00:04:24,090
If I open my file, I need to read it, okay.
79

80
00:04:24,090 --> 00:04:27,650
That's why here for the mode I will use r
80

81
00:04:27,650 --> 00:04:31,140
and after that here what I need to say? I say as file
81

82
00:04:31,140 --> 00:04:35,320
right and here before showing something
82

83
00:04:35,320 --> 00:04:37,660
I want to use only one function here
83

84
00:04:37,660 --> 00:04:40,670
self.txteditor.insert
84

85
00:04:40,670 --> 00:04:41,540
okay
85

86
00:04:41,540 --> 00:04:43,960
And from the first one
86

87
00:04:43,960 --> 00:04:47,270
1.0 and after that here what I need to use?
87

88
00:04:47,270 --> 00:04:50,170
I need to use file.read
88

89
00:04:50,170 --> 00:04:51,250
okay
89

90
00:04:51,250 --> 00:04:53,133
and if I run my application now.
90

91
00:04:55,330 --> 00:04:56,163
Run.
91

92
00:04:58,850 --> 00:05:03,850
Now here, for example, this is our existing file
92

93
00:05:05,170 --> 00:05:08,560
and now I want to try to open a new file.
93

94
00:05:08,560 --> 00:05:11,930
I will say file, open, alright.
94

95
00:05:11,930 --> 00:05:15,180
Here, our dialog window is here.
95

96
00:05:15,180 --> 00:05:16,914
Now I can open one of them, okay
96

97
00:05:16,914 --> 00:05:20,410
it doesn't matter, for example, that one.
97

98
00:05:20,410 --> 00:05:23,950
Hello, you see hello how are you Python is here
98

99
00:05:23,950 --> 00:05:28,700
But also the other text is also here, so what I need to do?
99

100
00:05:28,700 --> 00:05:30,570
I need to delete these guys, right
100

101
00:05:30,570 --> 00:05:33,970
and here before inserting
101

102
00:05:33,970 --> 00:05:35,980
I need to say here before inserting
102

103
00:05:36,820 --> 00:05:40,260
self.texteditor.delete
103

104
00:05:40,260 --> 00:05:42,060
and here I will say
104

105
00:05:42,060 --> 00:05:44,940
from the first one until end
105

106
00:05:45,880 --> 00:05:47,823
okay, and I will say END.
106

107
00:05:49,130 --> 00:05:52,050
Now if I try to run it again
107

108
00:05:53,640 --> 00:05:57,870
now it's okay, that one. This our existing file, right
108

109
00:05:57,870 --> 00:06:00,410
and now I want to open a new one. Open
109

110
00:06:01,400 --> 00:06:04,110
and let's use that one.
110

111
00:06:04,110 --> 00:06:06,310
You see hello how are you python
111

112
00:06:06,310 --> 00:06:09,550
and now it works. Also what we can do here...
112

113
00:06:12,700 --> 00:06:15,933
we can use here another title.
113

114
00:06:18,924 --> 00:06:23,160
For example, we can change title for our text editor
114

115
00:06:23,160 --> 00:06:24,560
and let me also show it.
115

116
00:06:24,560 --> 00:06:27,280
Also I want to show you something else.
116

117
00:06:27,280 --> 00:06:29,380
For example here...
117

118
00:06:29,380 --> 00:06:31,030
if I click open
118

119
00:06:31,030 --> 00:06:32,640
and if I say cancel
119

120
00:06:33,540 --> 00:06:35,550
this is also to do, what we need to do.
120

121
00:06:35,550 --> 00:06:39,310
I want to use here except look and I will say here
121

122
00:06:39,310 --> 00:06:43,530
return, okay, to do that and after that here what I need to do?
122

123
00:06:43,530 --> 00:06:48,120
As I said I want to change my title of my application
123

124
00:06:48,120 --> 00:06:50,210
and I will say self.parent
124

125
00:06:52,110 --> 00:06:53,613
Okay, dot title.
125

126
00:06:55,900 --> 00:06:58,650
Actually, so we can say
126

127
00:06:58,650 --> 00:07:00,400
self.title
127

128
00:07:00,400 --> 00:07:04,300
no, we need to say here parent, actually
128

129
00:07:04,300 --> 00:07:06,610
or here...
129

130
00:07:06,610 --> 00:07:08,293
Why is like that?
130

131
00:07:10,690 --> 00:07:12,860
self.title let's use...
131

132
00:07:14,320 --> 00:07:15,910
self.title
132

133
00:07:19,810 --> 00:07:22,390
Yes, we need to say parent but what's wrong here?
133

134
00:07:22,390 --> 00:07:25,120
I don't know. Title...
134

135
00:07:25,120 --> 00:07:28,350
and here let me say...
135

136
00:07:28,350 --> 00:07:29,183
Note
136

137
00:07:30,134 --> 00:07:31,940
Let me try it, okay.
137

138
00:07:31,940 --> 00:07:36,770
NotePad, and I will say here Now Editing
138

139
00:07:36,770 --> 00:07:38,550
something like that, okay
139

140
00:07:38,550 --> 00:07:40,750
and if I run my application now
140

141
00:07:45,010 --> 00:07:47,710
and here, file, open
141

142
00:07:48,610 --> 00:07:50,040
and I will open that one
142

143
00:07:50,900 --> 00:07:52,960
and you see now editing is okay
143

144
00:07:52,960 --> 00:07:54,993
but what I want to do, I want to
144

145
00:07:54,993 --> 00:07:58,843
display this file name, okay, the file I opened
145

146
00:07:59,860 --> 00:08:01,540
so how can I do that?
146

147
00:08:01,540 --> 00:08:02,940
Here...
147

148
00:08:02,940 --> 00:08:05,080
what I need to do is here, right.
148

149
00:08:05,080 --> 00:08:08,370
Notepad now editing and here I will say
149

150
00:08:08,370 --> 00:08:09,310
str
150

151
00:08:11,403 --> 00:08:15,080
Notepad Now Editing and here I will use
151

152
00:08:15,080 --> 00:08:16,420
plus str
152

153
00:08:17,960 --> 00:08:20,283
and self url.filename
153

154
00:08:25,470 --> 00:08:27,220
sorry, url.split
154

155
00:08:28,950 --> 00:08:33,160
and here I will split by slash, okay
155

156
00:08:33,160 --> 00:08:36,720
and here let's also use
156

157
00:08:37,830 --> 00:08:39,480
square brackets minus one.
157

158
00:08:39,480 --> 00:08:42,230
Why is like that? Let me here.
158

159
00:08:42,230 --> 00:08:44,610
First of all I want to show you something.
159

160
00:08:44,610 --> 00:08:47,500
Print out URL, okay, you'll understand why
160

161
00:08:47,500 --> 00:08:49,760
I am using split and also...
161

162
00:08:50,980 --> 00:08:54,453
inverse of my list I say URL, okay.
162

163
00:08:58,620 --> 00:09:01,748
So here I will use open
163

164
00:09:01,748 --> 00:09:05,153
and now our file name is this one, okay.
164

165
00:09:06,150 --> 00:09:10,500
and you see now NotePad Now Editing is our file name
165

166
00:09:10,500 --> 00:09:13,853
and here also Python returns for us.
166

167
00:09:15,010 --> 00:09:17,050
You see that one. This is Python.
167

168
00:09:17,050 --> 00:09:21,010
This is URL variable. But what we are doing?
168

169
00:09:21,010 --> 00:09:24,651
We are splitting our URL by slash, right
169

170
00:09:24,651 --> 00:09:27,810
and the first one will be that one, okay.
170

171
00:09:27,810 --> 00:09:29,792
This is a list, it will return us a list.
171

172
00:09:29,792 --> 00:09:32,050
Even, let's say here...
172

173
00:09:32,050 --> 00:09:32,883
split
173

174
00:09:34,367 --> 00:09:36,110
this is split...
174

175
00:09:37,400 --> 00:09:39,813
by slash, okay.
175

176
00:09:42,890 --> 00:09:46,110
Now I want to open another file
176

177
00:09:46,110 --> 00:09:48,490
and let's use that one.
177

178
00:09:48,490 --> 00:09:52,290
Okay and I will close it. Let's check our list.
178

179
00:09:52,290 --> 00:09:55,890
You see this is our list, the first item is that one
179

180
00:09:55,890 --> 00:10:00,380
second one is that one and our file name is that one.
180

181
00:10:00,380 --> 00:10:03,643
So if I want to use that one, what I am to use here?
181

182
00:10:04,892 --> 00:10:08,940
I need to use reverse of my list, okay
182

183
00:10:08,940 --> 00:10:11,760
and the first, that one, that means
183

184
00:10:11,760 --> 00:10:15,920
I will get my name of my file, okay.
184

185
00:10:15,920 --> 00:10:20,920
This is how we can use openFile dialogue for our applications.
185

186
00:10:22,840 --> 00:10:24,713
For now let's all see in the next.
