1
00:00:00,750 --> 00:00:03,090
Hello and welcome to this video.

2
00:00:03,090 --> 00:00:11,850
This video is going to be the part one of a series of videos on creatine a calculator with Python.

3
00:00:11,860 --> 00:00:17,610
The first thing you need to do is open up a python shell so the way you access it is fine.

4
00:00:17,610 --> 00:00:24,530
The python folder so if you go into your program file as a python folder and just click on the Idol

5
00:00:25,000 --> 00:00:26,880
and that will launch the shell.

6
00:00:26,880 --> 00:00:32,630
So once you've got the shell open we need to open up a new file so click on File.

7
00:00:32,930 --> 00:00:42,740
New file and this file here is where we will write the code that will build the calculator the first

8
00:00:42,740 --> 00:00:51,000
and I recommend you do a save this file save as a python file so you do safe has and then keep it whatever

9
00:00:51,000 --> 00:00:52,560
name you want.

10
00:00:52,560 --> 00:00:56,790
He's already got the python file format here so you don't need to worry about that.

11
00:00:56,790 --> 00:00:57,960
Just give it a name.

12
00:00:58,480 --> 00:01:01,230
I'm going to call mine calculator

13
00:01:03,720 --> 00:01:10,050
calculator and I just press save and that will save it.

14
00:01:10,080 --> 00:01:13,180
I wanted to save on my desktop so I click save.

15
00:01:13,200 --> 00:01:18,330
So this file now is now a python file.

16
00:01:18,330 --> 00:01:22,170
The first thing I want to do is import a library.

17
00:01:22,170 --> 00:01:31,530
The library I want to import is called T counter is a library used to generate or create graphical user

18
00:01:31,710 --> 00:01:33,030
interface.

19
00:01:33,030 --> 00:01:35,310
So to do that we need to import it.

20
00:01:35,310 --> 00:01:40,500
So you type in from then you specify the name of the module.

21
00:01:40,590 --> 00:01:50,850
So this is a module is called teak into space and type in the word import space Asterix and that will

22
00:01:50,850 --> 00:01:54,810
import the library into the application for me to you.

23
00:01:55,290 --> 00:02:01,670
The next thing I want to do is create a class a class basically is a template for creating objects.

24
00:02:01,740 --> 00:02:09,150
So our typing class followed by the name I want to give the class I'll call it application.

25
00:02:12,250 --> 00:02:21,570
And when you create a class you can also passing arguments all parameters into it and I'm going to pass

26
00:02:21,570 --> 00:02:28,290
him a frame has an argument into that class.

27
00:02:28,590 --> 00:02:33,200
And when you create a class you also have to put a call on there.

28
00:02:34,470 --> 00:02:39,620
So this would be the main class for the calculator.

29
00:02:39,620 --> 00:02:48,370
Not as a passing frame that a frame basically is used to group and organize other widgets.

30
00:02:48,420 --> 00:02:55,680
So it's kind of like a container object for all the widgets the application is going to use.

31
00:02:56,400 --> 00:03:04,950
So inside this class I'm going to create a function or a method so to define a function you type in

32
00:03:04,950 --> 00:03:07,070
the what the f followed by the name.

33
00:03:07,070 --> 00:03:20,370
So I'm going to use the in it c to underscore in it on the score and then in parentheses is who are

34
00:03:20,370 --> 00:03:24,780
passing the any arguments I want inside that function.

35
00:03:24,930 --> 00:03:35,040
This on the score you need on the score function is a special function that is called when an instance

36
00:03:35,220 --> 00:03:37,440
of a class is created.

37
00:03:37,830 --> 00:03:41,760
So you use that to initialize that instance.

38
00:03:41,760 --> 00:03:46,290
So inside the parentheses I'm going to pass same two arguments.

39
00:03:46,290 --> 00:03:59,400
I'm going to passing herself variable and master the self is a reference to the current instance of

40
00:03:59,430 --> 00:04:01,120
the class.

41
00:04:01,170 --> 00:04:01,570
OK.

42
00:04:01,580 --> 00:04:03,690
And that's what that self is.

43
00:04:03,690 --> 00:04:09,170
And then the master represents the parent widget.

44
00:04:09,180 --> 00:04:17,100
So now let's initialize the frame so to initialize the frame we're going to use a special built in function

45
00:04:17,520 --> 00:04:20,700
and the built in function is called Super.

46
00:04:21,840 --> 00:04:29,880
So inside the parentheses are passing some of the super function is a built in function which returns

47
00:04:30,150 --> 00:04:33,410
a proxy object to delegates.

48
00:04:33,510 --> 00:04:34,710
Method calls.

49
00:04:35,100 --> 00:04:45,090
So he uses that to delegate method calls to a class which can either be a parent or a sibling in nature.

50
00:04:45,360 --> 00:04:56,100
So inside a super function I pass Tim the application class here and also a reference to the cell variable.

51
00:04:56,230 --> 00:05:04,390
And here I'm using the underscore in it again initialize the master widget.

52
00:05:04,760 --> 00:05:10,440
This master also is known as the parent widget so we initialize in it.

53
00:05:10,440 --> 00:05:15,690
Here to save time I've added a few lines of code here.

54
00:05:15,730 --> 00:05:22,990
I've added these lines of code so this self again is a is a variable.

55
00:05:23,240 --> 00:05:29,180
It's a reference to an instance of a class or an object that is created.

56
00:05:29,210 --> 00:05:37,810
So here I am set in these two blank and then here I'm using the self again the user input.

57
00:05:37,820 --> 00:05:43,640
This was going to be a user input variable and I've set that to equals to this string.

58
00:05:43,760 --> 00:05:51,450
Var basically this string var is going to hold a string and the default value is blank.

59
00:05:51,500 --> 00:05:56,360
But I've set this to make sure it holds a string value.

60
00:05:57,710 --> 00:06:00,710
Then here we've got the create method.

61
00:06:00,710 --> 00:06:08,460
The grid metal basically is used to register a widget with the great geometry manager.

62
00:06:08,540 --> 00:06:17,840
So if you don't do this the widget will exist internally but it will not be visible on the screen so

63
00:06:17,840 --> 00:06:25,420
the greed is used to register widgets with the jewel military manager.

64
00:06:25,460 --> 00:06:33,980
The geometric manager is used to manage the placement and the layout of the elements of the go to create

65
00:06:34,010 --> 00:06:38,300
on the score widget function which will use to create widgets.

66
00:06:38,360 --> 00:06:40,520
So that's it for this part.

67
00:06:40,520 --> 00:06:41,540
Thanks for watching.

68
00:06:41,540 --> 00:06:42,160
Bye for now.
