1 00:00:00,510 --> 00:00:06,990 Hello and welcome to part two of creatine a calculator with Python. 2 00:00:06,990 --> 00:00:14,210 In this part we are going to focus on creatine all the buttons for the calculator. 3 00:00:14,700 --> 00:00:21,300 So we're going to create a function within that function will create the buttons for the calculator. 4 00:00:22,140 --> 00:00:29,720 So let's create a function that will be responsible for creating art buttons for the calculator. 5 00:00:29,790 --> 00:00:34,560 So to create a function you do D F space followed by the name. 6 00:00:34,560 --> 00:00:36,980 So I'm gonna call it create. 7 00:00:37,050 --> 00:00:38,320 I'm going to use this here. 8 00:00:38,340 --> 00:00:41,270 Create on the score 9 00:00:43,780 --> 00:00:45,510 widgets. 10 00:00:45,990 --> 00:01:01,970 So there will be widgets and I am going to passing self the self variable into that function and inside 11 00:01:03,690 --> 00:01:09,860 this function is where we define the various but the user input. 12 00:01:09,860 --> 00:01:13,340 He's going to be stored as an Entry widget. 13 00:01:13,530 --> 00:01:26,040 So inside this function this create function we are going to make reference to the Entry widget to save 14 00:01:26,040 --> 00:01:33,270 time I have had it some line of code here to the function that I created. 15 00:01:33,270 --> 00:01:40,820 So here we have got a reference to the Self Variable the user on the score input. 16 00:01:41,040 --> 00:01:45,300 We're setting this to a course to entry the. 17 00:01:45,480 --> 00:01:54,870 This refers to the Entry widget the Entry widget is basically used to accept single line text strings 18 00:01:55,140 --> 00:01:57,510 from a user. 19 00:01:57,510 --> 00:02:06,780 If you want to display multiple lines of text that can be edited then you need to use a text widget 20 00:02:06,890 --> 00:02:07,830 instead. 21 00:02:08,100 --> 00:02:16,470 If you want to display one or more lines of text that cannot be modified by the user then you should 22 00:02:16,470 --> 00:02:20,370 consider using a label widget. 23 00:02:20,370 --> 00:02:29,550 So here we're using an Entry widget to accept a single line text strings of input from the user. 24 00:02:29,580 --> 00:02:31,410 And here we pass on it. 25 00:02:31,440 --> 00:02:35,250 This is the background color beekeeper friends or background color. 26 00:02:35,700 --> 00:02:40,490 And this is a hex value and given it you don't have to use x value. 27 00:02:40,500 --> 00:02:42,270 You can just type in the color you want. 28 00:02:42,300 --> 00:02:50,720 If it's brown white enclose it in quotes and here we're referring to the border be these towns for border. 29 00:02:51,090 --> 00:02:55,120 So the default values usually impacts in pixels. 30 00:02:55,200 --> 00:02:58,490 So I'm setting the value here to twenty nine. 31 00:02:58,500 --> 00:03:06,120 So this will be the size of the border and the value is in picks. 32 00:03:06,840 --> 00:03:11,980 And here we insert in the width we're setting the width 2 4. 33 00:03:12,990 --> 00:03:20,070 So there is a difference between the inset width and the actual with the inset which basically is the 34 00:03:20,070 --> 00:03:23,060 width of the insertion cursor. 35 00:03:23,100 --> 00:03:32,380 So it references the height so it's height is determined by the tallest item in its line. 36 00:03:32,490 --> 00:03:38,510 The default values usually two pixels but offset it to four. 37 00:03:38,520 --> 00:03:46,840 And here that with the width basically refers to the width of the widget in characters not pixel value. 38 00:03:48,150 --> 00:03:55,620 And this usually mesh measured measured according to the current font size. 39 00:03:55,620 --> 00:04:02,090 And here we've got a reference to the font so the font I've specified to use is for dinner. 40 00:04:02,610 --> 00:04:07,020 When you specify values you need to enclose them in quotes. 41 00:04:07,020 --> 00:04:16,930 If they are text or string values and this 20 year refers to the size of the font bold means I want 42 00:04:16,930 --> 00:04:20,410 it to be bold. 43 00:04:21,210 --> 00:04:29,540 Here we've got a text variable here which I'm setting too close to the Self Variable the user input. 44 00:04:29,730 --> 00:04:36,140 And I'm using to justify here to justify its position to the right. 45 00:04:36,140 --> 00:04:42,780 And here we we are using a great method for the input. 46 00:04:42,780 --> 00:04:46,780 And this is a column spend for the greeting. 47 00:04:47,580 --> 00:04:53,580 And on the screen of the calculator we are setting a default value of zero. 48 00:04:53,580 --> 00:05:04,780 So the calculator will have zero on the screen as a default so I have now added a function a value here. 49 00:05:04,790 --> 00:05:05,890 This is for the button. 50 00:05:05,900 --> 00:05:06,630 So I've stopped. 51 00:05:06,650 --> 00:05:10,450 This is the code for the button here. 52 00:05:10,460 --> 00:05:16,610 So this is going to be the number seven button on the calculator. 53 00:05:16,610 --> 00:05:19,080 So this is a piece of code I've got for it. 54 00:05:19,640 --> 00:05:24,410 So here again we're referring to it as putting one dot self. 55 00:05:24,410 --> 00:05:28,940 This would be the variable set in that two equals two button. 56 00:05:29,570 --> 00:05:36,020 And inside the button method we've got reference to the BJP which is a background color. 57 00:05:36,020 --> 00:05:38,110 I've given it this has a background color. 58 00:05:38,570 --> 00:05:43,140 And that is the border have set the borders size to 12. 59 00:05:44,030 --> 00:05:47,980 Usually you will be in pixel values text. 60 00:05:47,990 --> 00:05:51,740 This is a text that will appear on the button. 61 00:05:51,770 --> 00:05:54,320 It will have number seven on it. 62 00:05:54,320 --> 00:06:00,080 This P A the X refers to external X padding. 63 00:06:00,200 --> 00:06:10,300 So this dimension is added to the left and the right outer or outside of the pages of the widget. 64 00:06:10,520 --> 00:06:17,270 So the dimensions you apply to the left and the right outside of the widget. 65 00:06:17,270 --> 00:06:20,050 So that's what you use for the EPA. 66 00:06:20,160 --> 00:06:24,050 So this is a value you have given it next to it. 67 00:06:24,050 --> 00:06:25,530 We've got Patty. 68 00:06:25,810 --> 00:06:29,750 Patty basically is for external y padding y. 69 00:06:29,750 --> 00:06:37,910 This refers to the padding on the x axis is Party Y refers to a padding on the y axis. 70 00:06:37,910 --> 00:06:47,780 So it's basically external padding and the dimension is added to padding above and below the widget. 71 00:06:49,790 --> 00:06:58,100 And here we've got the font set the value of the font to help Vertica and this size is 20 and up made 72 00:06:58,100 --> 00:06:59,320 a bold. 73 00:06:59,330 --> 00:06:59,930 Here we go. 74 00:06:59,930 --> 00:07:08,090 Command we said that to Lambda lump basically is an anonymous function. 75 00:07:08,240 --> 00:07:15,820 So it's a key word used to describe an anonymous function. 76 00:07:15,860 --> 00:07:19,640 So here we've got a self button to click. 77 00:07:19,750 --> 00:07:25,100 We've not defined this method yet but we are touching it to this here. 78 00:07:25,100 --> 00:07:32,240 So later once we create the button line break the once we write the function this for this button don't 79 00:07:32,240 --> 00:07:32,980 click. 80 00:07:33,080 --> 00:07:41,330 When someone clicks on the numbers number seven button it will fire off the logic inside this button 81 00:07:41,330 --> 00:07:43,140 dot click method. 82 00:07:44,150 --> 00:07:52,010 And here we have got a grid with row of to the row number. 83 00:07:52,190 --> 00:07:58,150 Basically this refers to the run number into which you want to insert the widget. 84 00:07:58,220 --> 00:08:00,810 So the counting starts from zero. 85 00:08:00,860 --> 00:08:07,100 And the default is the next high unnumbered of on occupied row. 86 00:08:07,100 --> 00:08:13,200 So it basically refers to where you want to insert the widget. 87 00:08:13,520 --> 00:08:22,730 I'm not said I want to insert it after the second row the column number basically refers to where you 88 00:08:22,730 --> 00:08:26,830 want the widget to be greeted where you want the grid to apply. 89 00:08:27,140 --> 00:08:28,300 This column here. 90 00:08:28,780 --> 00:08:29,580 OK. 91 00:08:29,820 --> 00:08:34,490 I've set it to equal to zero which is the default. 92 00:08:34,580 --> 00:08:41,890 I've also set the button here with a value of sticky sticky basically. 93 00:08:41,900 --> 00:08:49,220 This option determines how to distribute any extra space within the cell. 94 00:08:49,310 --> 00:08:52,630 That is not taken up or by the widget. 95 00:08:52,730 --> 00:08:59,620 So any extra space that the widget doesn't occupy is sorted out using this sticky. 96 00:08:59,990 --> 00:09:08,330 So it would distribute the extra spaces if you do not provide a sticky attribute the default behavior 97 00:09:08,420 --> 00:09:11,090 is to sent out the widget in the cell. 98 00:09:11,900 --> 00:09:15,910 So I've given it a valley of W. what that will do. 99 00:09:15,920 --> 00:09:23,300 It will stretch the widget both horizontally and vertically to feel the cell. 100 00:09:25,340 --> 00:09:31,950 So this button is the number seven all the rest of the buttons are going to be identical. 101 00:09:32,270 --> 00:09:37,670 So what I'm going to do I'm just going to copy this piece of code here and just change the relevant 102 00:09:37,790 --> 00:09:41,200 button number. 103 00:09:41,270 --> 00:09:46,310 So I've added the other buttons that the calculator would need. 104 00:09:46,310 --> 00:09:48,720 So this was what we did together. 105 00:09:48,800 --> 00:09:49,550 Number seven. 106 00:09:49,850 --> 00:09:54,830 So basically the code is the same all up don't just change the text number. 107 00:09:54,830 --> 00:10:00,910 So this will not be button number eight and this will be button number nine. 108 00:10:00,990 --> 00:10:07,430 This will be button number for this with button number five. 109 00:10:07,500 --> 00:10:09,860 This reporter number six. 110 00:10:09,960 --> 00:10:13,530 So let me scroll down so you can see the other buttons 111 00:10:16,320 --> 00:10:23,800 this is text but no one say this is 2 3. 112 00:10:24,770 --> 00:10:26,150 Patient Zero. 113 00:10:26,290 --> 00:10:29,150 This will be the addition button. 114 00:10:31,470 --> 00:10:41,450 This will be the subtraction button and this will be the multiplication button. 115 00:10:41,730 --> 00:10:49,410 And this is the division the division is used to division with a slash. 116 00:10:49,470 --> 00:10:53,060 That's how you identify division in Python. 117 00:10:53,160 --> 00:10:56,490 So you use slash most programming languages actually. 118 00:10:56,500 --> 00:11:05,190 He uses a slash to indicate a division and also of course the equals to button. 119 00:11:05,190 --> 00:11:08,940 So when you do the calculation that you want an equal stop button. 120 00:11:08,940 --> 00:11:11,670 So this is the equals two button here. 121 00:11:11,880 --> 00:11:20,070 And I've also got a club button which I'm calling I'm gonna have the text set as a C so you can clear 122 00:11:20,190 --> 00:11:21,660 what's on the screen. 123 00:11:22,140 --> 00:11:27,180 So that is all our buttons that we're going to need for the calculator. 124 00:11:27,930 --> 00:11:29,760 So that's it for this lecture. 125 00:11:29,760 --> 00:11:30,660 Thanks for watching. 126 00:11:30,930 --> 00:11:31,810 Bye for now.