0
1
00:00:04,288 --> 00:00:05,367
<v Volkan>Okay, in previous lecture we learned </v>
1

2
00:00:05,367 --> 00:00:08,090
how we can use open file dialogue, and in this lecture
2

3
00:00:08,090 --> 00:00:11,210
we are going to learn how we can use Save File Dialogue.
3

4
00:00:11,210 --> 00:00:12,340
To do that what we need to do here,
4

5
00:00:12,340 --> 00:00:14,860
let me run our application.
5

6
00:00:14,860 --> 00:00:17,850
And it's here, let me add a button here,
6

7
00:00:17,850 --> 00:00:19,700
next to this one, okay.
7

8
00:00:19,700 --> 00:00:22,120
And this is our open file dialog window
8

9
00:00:22,120 --> 00:00:25,403
and now, so what I need to do here.
9

10
00:00:26,630 --> 00:00:29,830
Something wrong, it says, and, file not found.
10

11
00:00:29,830 --> 00:00:32,030
Okay, no problem.
11

12
00:00:32,030 --> 00:00:32,863
And here what we need to do,
12

13
00:00:32,863 --> 00:00:34,550
we need to create another button, right.
13

14
00:00:34,550 --> 00:00:38,170
To do that I will come here and click here,
14

15
00:00:38,170 --> 00:00:40,670
Cntrol + D, duplicate my button okay.
15

16
00:00:40,670 --> 00:00:44,850
And I will name button two, that one will be Save.
16

17
00:00:44,850 --> 00:00:49,620
And my function name will be saveFile, right.
17

18
00:00:49,620 --> 00:00:50,453
And here, what I need to do
18

19
00:00:50,453 --> 00:00:53,517
I need to create this definition, def, saveFile.
19

20
00:00:55,670 --> 00:00:57,210
And here, what I need to do,
20

21
00:00:57,210 --> 00:01:00,110
simply, I will say pass for now, okay.
21

22
00:01:00,110 --> 00:01:05,110
And now, let's run our application and see our buttons.
22

23
00:01:05,150 --> 00:01:08,480
As you see our buttons are here but
23

24
00:01:08,480 --> 00:01:11,900
I want to place my button here, okay, next to the first one.
24

25
00:01:11,900 --> 00:01:12,733
So how can I do that?
25

26
00:01:12,733 --> 00:01:15,160
To do that I need to use here, after pack
26

27
00:01:15,160 --> 00:01:19,340
I will say, side is equal to LEFT okay,
27

28
00:01:19,340 --> 00:01:21,600
and for the other one also, we need to do that,
28

29
00:01:21,600 --> 00:01:24,203
side is equal to LEFT.
29

30
00:01:25,840 --> 00:01:28,223
And now if I run my application,
30

31
00:01:29,950 --> 00:01:32,990
as you see now they are on the left side, this is right
31

32
00:01:32,990 --> 00:01:35,590
but I want to move them somewhere here, okay.
32

33
00:01:35,590 --> 00:01:36,880
So, how can I do that, to do that,
33

34
00:01:36,880 --> 00:01:39,629
I can use x, pad x right?
34

35
00:01:39,629 --> 00:01:43,163
I can add pad for my buttons.
35

36
00:01:44,070 --> 00:01:46,893
Let's do it here for the first button I will say,
36

37
00:01:47,880 --> 00:01:52,410
pad x value, let's say 170, okay.
37

38
00:01:52,410 --> 00:01:55,580
And if I run my application, I mean to fix it again,
38

39
00:01:55,580 --> 00:01:57,850
now and there you see is here will be all
39

40
00:01:57,850 --> 00:02:01,020
the added pad for our first button.
40

41
00:02:01,020 --> 00:02:04,060
But the problem here, when we add pad
41

42
00:02:04,060 --> 00:02:07,120
we add this pad for both sides, what I mean here,
42

43
00:02:07,120 --> 00:02:09,930
the left side and for right side too,
43

44
00:02:09,930 --> 00:02:13,160
we are adding this pad for left and also for right side.
44

45
00:02:13,160 --> 00:02:14,900
So, how can I solve this problem?
45

46
00:02:14,900 --> 00:02:19,700
Now here there is 170 pixels pad,
46

47
00:02:19,700 --> 00:02:24,010
and also for this side also, we have 170 pixels pad.
47

48
00:02:24,010 --> 00:02:26,750
And here we need to use something else here,
48

49
00:02:26,750 --> 00:02:30,710
if you want to add pad only for one side,
49

50
00:02:30,710 --> 00:02:32,700
here what you need to do you need to come here say,
50

51
00:02:32,700 --> 00:02:35,922
and use parentheses and 170,
51

52
00:02:35,922 --> 00:02:39,500
and for the right side lets say 20, okay.
52

53
00:02:39,500 --> 00:02:42,380
And this will solve our problem.
53

54
00:02:42,380 --> 00:02:44,220
As you see now, it's now better,
54

55
00:02:44,220 --> 00:02:48,213
and this side we have 170 pad,
55

56
00:02:49,400 --> 00:02:52,940
for this side we have 20 pixels pad, okay?
56

57
00:02:52,940 --> 00:02:55,140
And after that what I need to do,
57

58
00:02:55,140 --> 00:02:56,823
now I need to create my,
58

59
00:02:58,340 --> 00:03:01,490
I need to create here a new variable, okay,
59

60
00:03:01,490 --> 00:03:05,528
for my save file, here what I will say?
60

61
00:03:05,528 --> 00:03:08,130
I will say myFile, let's name it, okay?
61

62
00:03:08,130 --> 00:03:11,150
Is equal to file dialogue, right.
62

63
00:03:11,150 --> 00:03:12,423
And after here what I will use,
63

64
00:03:12,423 --> 00:03:15,910
I will use ask save as file dialogue, okay.
64

65
00:03:15,910 --> 00:03:18,210
And our first parameter is mode, as you see
65

66
00:03:18,210 --> 00:03:21,220
it says mode, Control + P, and let's check it again.
66

67
00:03:21,220 --> 00:03:26,220
Mode CTR, and here for the first parameter I will say,
67

68
00:03:26,290 --> 00:03:29,910
mode is equal to, I will use w mode, of course.
68

69
00:03:29,910 --> 00:03:31,217
And after that what I need to do,
69

70
00:03:31,217 --> 00:03:36,217
I will use default, default extension, okay.
70

71
00:03:40,630 --> 00:03:44,790
And default extension will be .txt.
71

72
00:03:44,790 --> 00:03:45,623
Why is like that?
72

73
00:03:45,623 --> 00:03:48,010
Because, we have a text editor, right.
73

74
00:03:48,010 --> 00:03:50,440
It's like Notepad okay, and these text editors
74

75
00:03:50,440 --> 00:03:53,540
will use txt files, okay.
75

76
00:03:53,540 --> 00:03:58,540
For example, if you talk about an image editor,
76

77
00:03:58,970 --> 00:04:03,730
the image editor will use extension for jpeg or png, right?
77

78
00:04:03,730 --> 00:04:06,430
But for this kind of application, this editor,
78

79
00:04:06,430 --> 00:04:08,490
it will use txt files, okay?
79

80
00:04:08,490 --> 00:04:13,240
That's why we need to define our extension as txt.
80

81
00:04:13,240 --> 00:04:14,480
Okay, this is important.
81

82
00:04:14,480 --> 00:04:15,830
And after that here what I will say,
82

83
00:04:15,830 --> 00:04:20,830
I will say if myFile is None,
83

84
00:04:22,920 --> 00:04:27,760
that means if the users click Cancel button, okay,
84

85
00:04:27,760 --> 00:04:32,760
and I will say here return, and after that here
85

86
00:04:33,030 --> 00:04:34,100
what I need to do I need to get
86

87
00:04:34,100 --> 00:04:36,060
content of my text editor right.
87

88
00:04:36,060 --> 00:04:38,880
To that I will say, content is equal to
88

89
00:04:38,880 --> 00:04:42,620
text editor.get value, get function, right.
89

90
00:04:42,620 --> 00:04:47,610
And we already learned that so here, I will pass in 1.0,
90

91
00:04:47,610 --> 00:04:50,633
and my second parameter will be end-1c, okay?
91

92
00:04:53,370 --> 00:04:54,357
And after that, what I need to do here
92

93
00:04:54,357 --> 00:04:59,357
I need to use myFile, this is my file name, and write,
93

94
00:04:59,870 --> 00:05:02,960
write function, and I will pass in content.
94

95
00:05:02,960 --> 00:05:04,360
If I run my application now.
95

96
00:05:07,170 --> 00:05:10,940
Now if I say, let's come here and if I say,
96

97
00:05:10,940 --> 00:05:14,513
let's something here, hello.
97

98
00:05:17,850 --> 00:05:22,130
Hello Python, how are you?
98

99
00:05:22,130 --> 00:05:25,363
Okay, something like that, and if I say Save.
99

100
00:05:26,780 --> 00:05:29,713
As you see now this is my Save Dialogue Window.
100

101
00:05:30,610 --> 00:05:31,940
The Cancel is here, by the way,
101

102
00:05:31,940 --> 00:05:33,947
if the user clicks Cancel button,
102

103
00:05:35,970 --> 00:05:39,858
you see we say, if file is None, return, okay.
103

104
00:05:39,858 --> 00:05:42,606
For example, if I click Cancel, you see,
104

105
00:05:42,606 --> 00:05:44,510
I will not get an error, okay.
105

106
00:05:44,510 --> 00:05:46,260
And now let's do it again.
106

107
00:05:46,260 --> 00:05:49,970
Save, and here, let's name it bb, something like that, okay.
107

108
00:05:49,970 --> 00:05:54,450
And if I say Save, and now let's Open it, okay.
108

109
00:05:54,450 --> 00:05:56,660
And let's check it, Open.
109

110
00:05:56,660 --> 00:05:58,970
And as you see now, our bb file is here.
110

111
00:05:58,970 --> 00:06:01,870
Let's click it, and you see it's here,
111

112
00:06:01,870 --> 00:06:05,360
our text is also here, hello, Python how are you?
112

113
00:06:05,360 --> 00:06:08,580
Okay, this is how we can use Save File Dialogue
113

114
00:06:08,580 --> 00:06:09,790
for our applications.
114

115
00:06:09,790 --> 00:06:12,287
For now, that's all, see you in the next.
