0
1
00:00:05,280 --> 00:00:06,690
<v Instructor>In this lecture we are going to learn</v>
1

2
00:00:06,690 --> 00:00:09,800
how we can create ComboBoxes for our applications.
2

3
00:00:09,800 --> 00:00:12,990
And like before  do we need to create a variable
3

4
00:00:12,990 --> 00:00:16,887
here for our ComboBox and after that, we can create our ComboBox.
4

5
00:00:16,887 --> 00:00:17,860
To do that what I'll say.
5

6
00:00:17,860 --> 00:00:21,030
I will say months, this is my variable name
6

7
00:00:21,030 --> 00:00:25,630
and after that here I' need to create StringVar variables, okay?
7

8
00:00:25,630 --> 00:00:28,080
And my function is StringVar.
8

9
00:00:28,080 --> 00:00:29,590
And now, how we can create
9

10
00:00:29,590 --> 00:00:31,082
our ComboBox to do that I will say
10

11
00:00:31,082 --> 00:00:36,082
ComboBox=ttk.Combobox.
11

12
00:00:39,890 --> 00:00:43,150
And here our first parameter will be root.
12

13
00:00:43,150 --> 00:00:45,660
And the second one is a textvariable
13

14
00:00:49,030 --> 00:00:53,550
is equal to our variable months, okay?
14

15
00:00:53,550 --> 00:00:56,460
And after that here, months
15

16
00:00:59,170 --> 00:01:01,050
months okay?
16

17
00:01:01,050 --> 00:01:05,580
Now I can use grid geometry manager for my ComboBox
17

18
00:01:05,580 --> 00:01:08,920
to do that I will say here, for the row as you remember,
18

19
00:01:08,920 --> 00:01:11,250
this is our last row is ?
19

20
00:01:11,250 --> 00:01:12,730
It was five, okay?
20

21
00:01:12,730 --> 00:01:17,730
And, for ComboBox, I will say row is six and column is 0.
21

22
00:01:20,530 --> 00:01:25,070
Okay, and now, if I run my application I can see my ComboBox
22

23
00:01:26,480 --> 00:01:28,520
as you you see now, our ComboBox is here,
23

24
00:01:28,520 --> 00:01:30,240
but it's totally empty.
24

25
00:01:30,240 --> 00:01:32,390
So what we need to do, is we need to create variables
25

26
00:01:32,390 --> 00:01:34,480
for our ComboBox.
26

27
00:01:34,480 --> 00:01:37,580
To do that, what I need to do, I can come here, and say
27

28
00:01:38,800 --> 00:01:41,220
sorry, I said variables, we need to create values
28

29
00:01:41,220 --> 00:01:42,140
for our ComboBox.
29

30
00:01:42,140 --> 00:01:44,670
Here I need to use values, okay?
30

31
00:01:44,670 --> 00:01:47,067
This is my function name and after values here,
31

32
00:01:47,067 --> 00:01:49,810
I need to create a tuple list, okay?
32

33
00:01:49,810 --> 00:01:54,030
For my tuple list, let's say, January, the first one.
33

34
00:01:54,030 --> 00:01:58,263
Second one is, February,
34

35
00:01:59,970 --> 00:02:04,500
after that, March, and lets say
35

36
00:02:04,500 --> 00:02:07,310
last one is April, okay?
36

37
00:02:07,310 --> 00:02:12,110
Now, if I run my application, I can see also my values.
37

38
00:02:12,110 --> 00:02:15,030
Here, as you see  our wealth is here.
38

39
00:02:15,030 --> 00:02:17,730
But here there's a problem, for example if I click for
39

40
00:02:17,730 --> 00:02:22,330
March, and now you can see we can edit our ComboBox values.
40

41
00:02:22,330 --> 00:02:26,240
And how we can solve this problem, to do that here,
41

42
00:02:26,240 --> 00:02:31,240
I will come here, and this here, click, press enter here.
42

43
00:02:32,970 --> 00:02:37,970
I will say state is equal to read only, okay.
43

44
00:02:40,350 --> 00:02:45,350
If I use this function, now I can't edit my ComboBox values.
44

45
00:02:46,130 --> 00:02:49,170
For example, for March we see we cannot edit it.
45

46
00:02:49,170 --> 00:02:53,820
For April, also, we can't edit our ComboBox values okay?
46

47
00:02:53,820 --> 00:02:56,680
And this is the first way how we can add values
47

48
00:02:56,680 --> 00:02:57,940
for our ComboBox.
48

49
00:02:57,940 --> 00:03:00,370
The other one, also, I want to show you something else now.
49

50
00:03:00,370 --> 00:03:05,370
Now let's delete this guy and here, for example if you,
50

51
00:03:06,440 --> 00:03:10,560
you can also use for loop to create your variables, okay?
51

52
00:03:10,560 --> 00:03:13,400
So it's always your values for ComboBox.
52

53
00:03:13,400 --> 00:03:14,480
How we can do that?
53

54
00:03:14,480 --> 00:03:17,880
That I will create here a list, empty list okay?
54

55
00:03:17,880 --> 00:03:20,580
Numbers is equal to this is
55

56
00:03:22,060 --> 00:03:25,420
our empty list is  here with it's numbers okay?
56

57
00:03:25,420 --> 00:03:28,700
And after I will say for i in range
57

58
00:03:28,700 --> 00:03:33,700
I will use range function from zero to, for example, 10.
58

59
00:03:33,743 --> 00:03:36,030
Okay and after that, what I need to do,
59

60
00:03:36,030 --> 00:03:40,150
I need to use a append method to add these guys to numbers
60

61
00:03:40,150 --> 00:03:43,550
to my numbers list, right?
61

62
00:03:43,550 --> 00:03:48,550
And here I say numbers.append 'i', okay?
62

63
00:03:49,870 --> 00:03:54,870
And here, for the values I will say numbers okay?
63

64
00:03:56,260 --> 00:04:01,260
And if I run my application now, and you see?
64

65
00:04:01,360 --> 00:04:04,430
From zero to nine, we have numbers are here.
65

66
00:04:04,430 --> 00:04:06,840
We can also use for loop if you want to create
66

67
00:04:08,183 --> 00:04:11,230
values for your ComboBox, okay?
67

68
00:04:11,230 --> 00:04:16,230
And also, I show you how to get the value of ComboBox.
68

69
00:04:16,310 --> 00:04:18,630
It's also important, it's also very, very simple,
69

70
00:04:18,630 --> 00:04:21,510
like before we need to use get Method, okay?
70

71
00:04:21,510 --> 00:04:26,510
And here, I will say print my ComboBox
71

72
00:04:26,849 --> 00:04:29,850
variable name was months, right?
72

73
00:04:29,850 --> 00:04:33,340
I will say months.get, that's all.
73

74
00:04:33,340 --> 00:04:38,340
If I run my application now, you see here let's fill it.
74

75
00:04:39,048 --> 00:04:41,310
Let's say again David.
75

76
00:04:41,310 --> 00:04:44,100
For password, one two three four.
76

77
00:04:44,100 --> 00:04:48,860
And male, and for that one,let's say seven, okay.
77

78
00:04:48,860 --> 00:04:53,260
If I hit Enter button, and let's check here our consol.
78

79
00:04:53,260 --> 00:04:58,150
See, your name, password not selected, and male, and also
79

80
00:04:58,150 --> 00:05:00,360
our ComboBox value is seven.
80

81
00:05:00,360 --> 00:05:04,440
This is how we can use ComboBoxes for our applications.
81

82
00:05:04,440 --> 00:05:06,440
For now that's all, see you in the next.
