1
00:00:00,540 --> 00:00:02,880
Hello and welcome to this video.

2
00:00:03,330 --> 00:00:12,300
This is going to be a two part video where we are going to create a digital clock using python from

3
00:00:12,300 --> 00:00:14,860
scratch.

4
00:00:14,850 --> 00:00:22,830
The first thing you need to do is open up the python shell and you can access the show by the python

5
00:00:22,830 --> 00:00:23,460
folder.

6
00:00:23,460 --> 00:00:30,040
So if you go to your Programs menu and inside the python folder just click on this.

7
00:00:30,120 --> 00:00:33,730
That is a point on Idol and will open up the shell.

8
00:00:33,750 --> 00:00:37,460
Once you've got the shell open we need to open up a new file.

9
00:00:37,470 --> 00:00:42,450
So you click file and click new file.

10
00:00:43,080 --> 00:00:53,370
So this new file here is where we'll actually write a program and any errors that occur will be displayed

11
00:00:53,400 --> 00:00:55,290
in the shell.

12
00:00:55,440 --> 00:00:59,240
We are going to use a few Python libraries.

13
00:00:59,580 --> 00:01:02,200
So we need to import them before we use them.

14
00:01:02,200 --> 00:01:07,490
The first the library you're going to import is the T counter library.

15
00:01:07,590 --> 00:01:17,920
So we need to import that by typing in from in lowercase space.

16
00:01:18,180 --> 00:01:33,140
And then the word T into space import and then Asterix and this will import the take into library.

17
00:01:33,270 --> 00:01:35,850
So it's available for us to use.

18
00:01:35,850 --> 00:01:43,080
So it's the first line you have to put in if you are going to use the T counter in your program.

19
00:01:43,080 --> 00:01:50,490
Take him to his library that is used to build user interfaces or interfaces in general.

20
00:01:51,060 --> 00:01:55,590
So we're going to import a sub library also from teak into.

21
00:01:56,220 --> 00:02:10,740
So we save from teak into this one is going to be called T T K next going to import the font.

22
00:02:10,750 --> 00:02:17,170
We want to use a font to take him also has fonts you can use.

23
00:02:17,210 --> 00:02:20,820
So to take into import

24
00:02:23,220 --> 00:02:23,820
font

25
00:02:26,670 --> 00:02:37,480
next we are going to import the time module cause we need to use that import time.

26
00:02:37,500 --> 00:02:47,070
Next I'm going to do is import a module for date time when we can make reference to that.

27
00:02:47,120 --> 00:02:48,200
So that's it.

28
00:02:48,200 --> 00:02:55,160
We've called all libraries next want to create a function.

29
00:02:55,160 --> 00:02:59,680
So the f is what you used to define a function.

30
00:03:00,390 --> 00:03:09,630
And I'm going to call this function quit so we'll use this to quit the application and I've been passing

31
00:03:09,740 --> 00:03:28,230
the arguments a R G S and the column makes you typing root dot this Troy

32
00:03:31,920 --> 00:03:41,670
inside the function we've just defined we've got an asterix followed by the word a R G is basically

33
00:03:41,670 --> 00:03:51,420
what that is used for is used inside function definitions and it's used to pass a non key word variable

34
00:03:51,420 --> 00:04:01,920
length so it will allow you to pass key non key word at variable length arguments as a list kind of

35
00:04:01,920 --> 00:04:11,760
like an array which allows you to pass several arguments provided they are not key words key words sometimes

36
00:04:11,820 --> 00:04:15,600
are reserved for the program so you can actually use.

37
00:04:15,690 --> 00:04:21,640
Next we've got the route dot destroy method what this will do it will.

38
00:04:21,630 --> 00:04:24,630
Course the main loop to exit.

39
00:04:24,660 --> 00:04:30,750
So when you are at the end of the way you close the window for the application does the method that

40
00:04:30,750 --> 00:04:37,980
would trigger the application to close it we just closed the session the next thing going to do is create

41
00:04:38,200 --> 00:04:40,410
an another function.

42
00:04:40,410 --> 00:04:43,410
This will be for our clock.

43
00:04:43,410 --> 00:04:53,700
So we're going to say D F I'm going to call it a clock on the score time you can call it whatever you

44
00:04:53,700 --> 00:04:58,860
want it doesn't really matter so I'm just calling it clock.

45
00:04:59,080 --> 00:04:59,820
All right.

46
00:04:59,940 --> 00:05:04,020
And you put a call on after that.

47
00:05:04,290 --> 00:05:07,530
Next thing I want to do is define a variable.

48
00:05:07,530 --> 00:05:15,840
I want to call a variable time and I'm going to set this variable to equal to the date time.

49
00:05:15,840 --> 00:05:18,080
Don't forget we import it did take time.

50
00:05:18,540 --> 00:05:19,800
So we can use it now.

51
00:05:19,800 --> 00:05:36,750
So to date time dot date time dot now which would give us to the current time the date or time method

52
00:05:36,900 --> 00:05:38,730
returns that current time.

53
00:05:38,730 --> 00:05:49,110
Also Emily milliseconds so I want to avoid that so to do that I'll need to format the time using a special

54
00:05:49,470 --> 00:05:51,190
format function.

55
00:05:51,540 --> 00:05:58,980
So to do that I've got to reference the time variable again and I'm going to have to set that to a course

56
00:05:58,980 --> 00:06:06,700
to an hour rapid round the variable dot.

57
00:06:06,930 --> 00:06:11,490
This is a special function here as call s t r f time.

58
00:06:11,490 --> 00:06:21,630
This is used to is a function used to format the time based on the arguments of past time.

59
00:06:21,660 --> 00:06:29,160
So I'm going to enclose that in double quotes and I'll pass in the format I want.

60
00:06:29,160 --> 00:06:42,690
So I want our call on and I want the minute I put cologne on I want these seconds and I close the double

61
00:06:42,690 --> 00:06:49,210
quotes close the parentheses and close the other parentheses.

62
00:06:49,230 --> 00:06:52,760
Next thing I want to do is find a way to display our time.

63
00:06:53,280 --> 00:07:09,780
So when I do text say T T which is text we can to set that to a course to the time variable so there

64
00:07:09,780 --> 00:07:13,930
is a functional metal code set don't touch this text.

65
00:07:13,980 --> 00:07:17,770
Dots time we text set.

66
00:07:17,880 --> 00:07:24,730
So this is a method and we're passing in this time variable here as the value.

67
00:07:24,750 --> 00:07:33,770
Next we want to trigger the clock so that eight stars of every one milliseconds.

68
00:07:33,800 --> 00:07:43,240
So we do route dot after and inside parentheses.

69
00:07:43,250 --> 00:07:52,320
We're passing the milliseconds a comma and then we're passing the function which is a clock block on

70
00:07:52,320 --> 00:07:53,970
the score time

71
00:07:57,330 --> 00:07:58,080
plus it.

72
00:07:58,130 --> 00:08:04,500
So we'll end this video here and in part two we will continue.

73
00:08:04,940 --> 00:08:06,300
So thanks for watching.

74
00:08:06,300 --> 00:08:07,010
And by phone.
