0
1
00:00:04,578 --> 00:00:05,870
<v Volkan>In this lecture we are going to learn</v>
1

2
00:00:05,870 --> 00:00:09,140
how we can create message boxes for our applications.
2

3
00:00:09,140 --> 00:00:11,210
Here I already create our template.
3

4
00:00:11,210 --> 00:00:12,620
But here what we need to do here,
4

5
00:00:12,620 --> 00:00:15,880
we need to say from tkinter,
5

6
00:00:15,880 --> 00:00:18,880
from tkinter import message box, okay.
6

7
00:00:18,880 --> 00:00:21,480
If you don't call this message box,
7

8
00:00:21,480 --> 00:00:23,250
if you don't import message box,
8

9
00:00:23,250 --> 00:00:26,920
we cannot use message box for our application, okay.
9

10
00:00:26,920 --> 00:00:28,290
So what we need to do here,
10

11
00:00:28,290 --> 00:00:30,440
I will create two buttons, okay,
11

12
00:00:30,440 --> 00:00:34,890
and button one is equal to I will say,
12

13
00:00:34,890 --> 00:00:39,371
I will use ttk module, dot button constructor method.
13

14
00:00:39,371 --> 00:00:44,000
And here root, first parameter, and second one
14

15
00:00:44,000 --> 00:00:46,803
will be, it's text property for text property
15

16
00:00:48,369 --> 00:00:52,470
I will say delete first, for first one,
16

17
00:00:52,470 --> 00:00:55,943
and the next one will be command.
17

18
00:00:56,780 --> 00:01:01,370
And command will be callback this is my definition name, okay.
18

19
00:01:01,370 --> 00:01:03,840
And now I will use grid geometry manager, of course.
19

20
00:01:03,840 --> 00:01:08,840
Grid, and here I will say row is equal to zero,
20

21
00:01:10,760 --> 00:01:15,760
and column is, column is equal to zero.
21

22
00:01:16,740 --> 00:01:20,600
Okay, and now I will press control and D,
22

23
00:01:20,600 --> 00:01:23,363
Control D, and now here, I will say button two,
23

24
00:01:24,710 --> 00:01:29,710
and for this one, I will say info only.
24

25
00:01:34,320 --> 00:01:38,170
And for callback function, I will name it call back two.
25

26
00:01:38,170 --> 00:01:40,790
Okay, I will create two different definitions
26

27
00:01:40,790 --> 00:01:42,770
for my buttons, okay.
27

28
00:01:42,770 --> 00:01:45,530
If I run my application now, actually I will get error,
28

29
00:01:45,530 --> 00:01:48,553
so I have to create here my callback function,
29

30
00:01:50,450 --> 00:01:55,340
callback, and here what I need to do
30

31
00:01:55,340 --> 00:01:57,940
let's say here pass for first one,
31

32
00:01:57,940 --> 00:02:02,633
and after that I need to create callback2, callback2.
32

33
00:02:04,500 --> 00:02:08,130
And here let's say pass again.
33

34
00:02:08,130 --> 00:02:09,883
Now if I run my application,
34

35
00:02:11,870 --> 00:02:13,610
as you see now here,
35

36
00:02:13,610 --> 00:02:16,860
I did not use grid geometry manager for button two.
36

37
00:02:16,860 --> 00:02:19,070
So let's do it also here.
37

38
00:02:19,070 --> 00:02:20,810
Actually no, it says I used used,
38

39
00:02:20,810 --> 00:02:24,500
but I need to say here  for the column will be one.
39

40
00:02:24,500 --> 00:02:28,740
Okay, and if I run it again, now as you see it's here.
40

41
00:02:28,740 --> 00:02:33,300
But let's add some pads here for top and also for left.
41

42
00:02:33,300 --> 00:02:35,833
How we can do that, here I can say,
42

43
00:02:37,212 --> 00:02:42,212
pad Y is equal to 25
43

44
00:02:43,000 --> 00:02:48,000
and pad X is let's say 50, okay.
44

45
00:02:48,440 --> 00:02:51,190
I think it will be more reasonable now.
45

46
00:02:51,190 --> 00:02:52,100
Yep, it is more reasonable
46

47
00:02:52,100 --> 00:02:55,120
and they are not very close now the buttons.
47

48
00:02:55,120 --> 00:02:56,460
So what we need to do now,
48

49
00:02:56,460 --> 00:02:58,340
we need to create our functions, right.
49

50
00:02:58,340 --> 00:03:02,470
For this, the click and connect functions for our buttons.
50

51
00:03:02,470 --> 00:03:04,030
And so what we need to do here
51

52
00:03:04,030 --> 00:03:07,940
for callback for the first button, the text is delete,
52

53
00:03:07,940 --> 00:03:11,450
right, the second one, the text is info.
53

54
00:03:11,450 --> 00:03:13,500
And here I need to show you how we can
54

55
00:03:13,500 --> 00:03:15,190
create message boxes.
55

56
00:03:15,190 --> 00:03:16,620
Here, firstly I will create
56

57
00:03:16,620 --> 00:03:19,210
a variable, and I will name it mbox, okay,
57

58
00:03:19,210 --> 00:03:21,360
it's message box, and after that I will say here
58

59
00:03:21,360 --> 00:03:23,060
message box dot
59

60
00:03:23,060 --> 00:03:24,670
As you see now there are many
60

61
00:03:24,670 --> 00:03:26,020
different message boxes actually,
61

62
00:03:26,020 --> 00:03:31,020
but here ask question, ask yes/no, ask yes/no/cancel,
62

63
00:03:34,050 --> 00:03:39,050
and for now I want to show you two different message boxes,
63

64
00:03:39,130 --> 00:03:40,810
okay, and it's enough.
64

65
00:03:40,810 --> 00:03:43,310
Usually all of them is very similar.
65

66
00:03:43,310 --> 00:03:46,660
First one is maybe ask question message box, okay.
66

67
00:03:46,660 --> 00:03:50,060
Ask questions, and here, the first one,
67

68
00:03:50,060 --> 00:03:54,580
the first parameter will be our text, okay.
68

69
00:03:54,580 --> 00:03:56,850
Sorry this is our title,
69

70
00:03:56,850 --> 00:03:59,263
and the other one will be our text.
70

71
00:04:01,150 --> 00:04:04,987
After delete I will say, for example,
71

72
00:04:04,987 --> 00:04:07,000
"Are you sure?"
72

73
00:04:07,000 --> 00:04:12,000
Okay, and other one is we can use here, icon,
73

74
00:04:12,000 --> 00:04:15,240
but let me show you run our application first
74

75
00:04:15,240 --> 00:04:18,090
and after that I will explain you how we can use icons,
75

76
00:04:18,090 --> 00:04:21,617
okay, and here, what we need to say, we need to say,
76

77
00:04:21,617 --> 00:04:22,450
"If Mbox."
77

78
00:04:28,388 --> 00:04:30,160
Mbox is equals equals yes, okay.
78

79
00:04:30,160 --> 00:04:33,760
Because we will have two buttons for ask question message box.
79

80
00:04:33,760 --> 00:04:36,229
First one is yes, the other one is no, okay,
80

81
00:04:36,229 --> 00:04:39,043
if the user clicks yes button,
81

82
00:04:39,043 --> 00:04:41,063
we need to say here something.
82

83
00:04:42,531 --> 00:04:45,040
Let's say print deleted, okay.
83

84
00:04:45,040 --> 00:04:47,180
If not, we need to say here,
84

85
00:04:47,180 --> 00:04:52,180
else, for else I will say print not deleted.
85

86
00:04:56,550 --> 00:04:58,550
And let me run our application now,
86

87
00:04:58,550 --> 00:05:01,260
and after that I want to you show you how we can use icons.
87

88
00:05:01,260 --> 00:05:04,283
If I click delete, as you can see now it's here.
88

89
00:05:06,906 --> 00:05:08,990
Actually, now here let me run it again,
89

90
00:05:08,990 --> 00:05:10,470
I want to show you something.
90

91
00:05:10,470 --> 00:05:12,530
It's here okay, delete.
91

92
00:05:12,530 --> 00:05:14,910
As you see delete is here, this is our title.
92

93
00:05:14,910 --> 00:05:15,800
Okay, the first one.
93

94
00:05:15,800 --> 00:05:18,470
And second one is our text, okay.
94

95
00:05:18,470 --> 00:05:21,370
But here, all the message box they have,
95

96
00:05:21,370 --> 00:05:23,670
they have specific icons, but if you want
96

97
00:05:23,670 --> 00:05:26,697
to use another icon for your message box you can do it.
97

98
00:05:26,697 --> 00:05:30,350
For example, here is ask question and that's
98

99
00:05:30,350 --> 00:05:32,228
why its icon is question mark, right.
99

100
00:05:32,228 --> 00:05:34,420
For example, if you want to use another icon,
100

101
00:05:34,420 --> 00:05:35,420
how you can do that.
101

102
00:05:38,097 --> 00:05:41,220
Let's close this one and here for icon property,
102

103
00:05:41,220 --> 00:05:45,812
we need to say here icon is, sorry,
103

104
00:05:45,812 --> 00:05:50,812
we need to say here icon is equal to for example
104

105
00:05:51,130 --> 00:05:52,651
let's use warning, okay,
105

106
00:05:52,651 --> 00:05:56,173
and now if I run my application again,
106

107
00:05:58,999 --> 00:06:03,010
delete, as you see now our icon is different.
107

108
00:06:03,010 --> 00:06:07,560
And now, if I say yes, and you see it's here,
108

109
00:06:07,560 --> 00:06:11,580
check here on our console it said deleted.
109

110
00:06:11,580 --> 00:06:15,700
If I say no, it said not deleted, okay.
110

111
00:06:15,700 --> 00:06:19,210
And also, let's create for the other message box
111

112
00:06:19,210 --> 00:06:23,060
it will be show info message box, okay.
112

113
00:06:23,060 --> 00:06:25,270
That one was ask question message box,
113

114
00:06:25,270 --> 00:06:27,000
here for callback two.
114

115
00:06:27,000 --> 00:06:29,860
I will create here, I will not create mbox
115

116
00:06:29,860 --> 00:06:32,470
because I will not use if and else statement this way.
116

117
00:06:32,470 --> 00:06:36,140
I will create message box, show info, okay.
117

118
00:06:39,880 --> 00:06:44,880
Here what I need to do, I need to use first one is my title.
118

119
00:06:45,600 --> 00:06:50,600
And second one will be, my text, okay, well done.
119

120
00:06:50,760 --> 00:06:54,341
And this one is the show info message box, it has
120

121
00:06:54,341 --> 00:06:56,510
only one button, let's run it now.
121

122
00:06:58,400 --> 00:07:02,030
If I click info button, you see it said well done
122

123
00:07:02,030 --> 00:07:04,304
and now it's our icon by default.
123

124
00:07:04,304 --> 00:07:07,230
This icon you can of course change it,
124

125
00:07:07,230 --> 00:07:08,410
like you can use icon
125

126
00:07:08,410 --> 00:07:11,320
and change your icon for your message box.
126

127
00:07:11,320 --> 00:07:15,380
And if I click okay, as you see, nothing happens
127

128
00:07:15,380 --> 00:07:18,580
but of course we can say here something.
128

129
00:07:18,580 --> 00:07:19,923
For example, we can say,
129

130
00:07:23,445 --> 00:07:24,950
print you clicked okay.
130

131
00:07:31,640 --> 00:07:35,123
And now, if I run it again,
131

132
00:07:37,090 --> 00:07:42,090
info, if I say okay, as you see now, you clicked okay.
132

133
00:07:42,610 --> 00:07:44,560
This is how we can use message boxes
133

134
00:07:44,560 --> 00:07:45,750
for our applications.
134

135
00:07:45,750 --> 00:07:47,733
For now, that's all, see you next.
