Hello and welcome to part two of creatine a calculator with Python.
In this part we are going to focus on creatine all the buttons for the calculator.
So we're going to create a function within that function will create the buttons for the calculator.
So let's create a function that will be responsible for creating art buttons for the calculator.
So to create a function you do D F space followed by the name.
So I'm gonna call it create.
I'm going to use this here.
Create on the score
widgets.
So there will be widgets and I am going to passing self the self variable into that function and inside
this function is where we define the various but the user input.
He's going to be stored as an Entry widget.
So inside this function this create function we are going to make reference to the Entry widget to save
time I have had it some line of code here to the function that I created.
So here we have got a reference to the Self Variable the user on the score input.
We're setting this to a course to entry the.
This refers to the Entry widget the Entry widget is basically used to accept single line text strings
from a user.
If you want to display multiple lines of text that can be edited then you need to use a text widget
instead.
If you want to display one or more lines of text that cannot be modified by the user then you should
consider using a label widget.
So here we're using an Entry widget to accept a single line text strings of input from the user.
And here we pass on it.
This is the background color beekeeper friends or background color.
And this is a hex value and given it you don't have to use x value.
You can just type in the color you want.
If it's brown white enclose it in quotes and here we're referring to the border be these towns for border.
So the default values usually impacts in pixels.
So I'm setting the value here to twenty nine.
So this will be the size of the border and the value is in picks.
And here we insert in the width we're setting the width 2 4.
So there is a difference between the inset width and the actual with the inset which basically is the
width of the insertion cursor.
So it references the height so it's height is determined by the tallest item in its line.
The default values usually two pixels but offset it to four.
And here that with the width basically refers to the width of the widget in characters not pixel value.
And this usually mesh measured measured according to the current font size.
And here we've got a reference to the font so the font I've specified to use is for dinner.
When you specify values you need to enclose them in quotes.
If they are text or string values and this 20 year refers to the size of the font bold means I want
it to be bold.
Here we've got a text variable here which I'm setting too close to the Self Variable the user input.
And I'm using to justify here to justify its position to the right.
And here we we are using a great method for the input.
And this is a column spend for the greeting.
And on the screen of the calculator we are setting a default value of zero.
So the calculator will have zero on the screen as a default so I have now added a function a value here.
This is for the button.
So I've stopped.
This is the code for the button here.
So this is going to be the number seven button on the calculator.
So this is a piece of code I've got for it.
So here again we're referring to it as putting one dot self.
This would be the variable set in that two equals two button.
And inside the button method we've got reference to the BJP which is a background color.
I've given it this has a background color.
And that is the border have set the borders size to 12.
Usually you will be in pixel values text.
This is a text that will appear on the button.
It will have number seven on it.
This P A the X refers to external X padding.
So this dimension is added to the left and the right outer or outside of the pages of the widget.
So the dimensions you apply to the left and the right outside of the widget.
So that's what you use for the EPA.
So this is a value you have given it next to it.
We've got Patty.
Patty basically is for external y padding y.
This refers to the padding on the x axis is Party Y refers to a padding on the y axis.
So it's basically external padding and the dimension is added to padding above and below the widget.
And here we've got the font set the value of the font to help Vertica and this size is 20 and up made
a bold.
Here we go.
Command we said that to Lambda lump basically is an anonymous function.
So it's a key word used to describe an anonymous function.
So here we've got a self button to click.
We've not defined this method yet but we are touching it to this here.
So later once we create the button line break the once we write the function this for this button don't
click.
When someone clicks on the numbers number seven button it will fire off the logic inside this button
dot click method.
And here we have got a grid with row of to the row number.
Basically this refers to the run number into which you want to insert the widget.
So the counting starts from zero.
And the default is the next high unnumbered of on occupied row.
So it basically refers to where you want to insert the widget.
I'm not said I want to insert it after the second row the column number basically refers to where you
want the widget to be greeted where you want the grid to apply.
This column here.
OK.
I've set it to equal to zero which is the default.
I've also set the button here with a value of sticky sticky basically.
This option determines how to distribute any extra space within the cell.
That is not taken up or by the widget.
So any extra space that the widget doesn't occupy is sorted out using this sticky.
So it would distribute the extra spaces if you do not provide a sticky attribute the default behavior
is to sent out the widget in the cell.
So I've given it a valley of W. what that will do.
It will stretch the widget both horizontally and vertically to feel the cell.
So this button is the number seven all the rest of the buttons are going to be identical.
So what I'm going to do I'm just going to copy this piece of code here and just change the relevant
button number.
So I've added the other buttons that the calculator would need.
So this was what we did together.
Number seven.
So basically the code is the same all up don't just change the text number.
So this will not be button number eight and this will be button number nine.
This will be button number for this with button number five.
This reporter number six.
So let me scroll down so you can see the other buttons
this is text but no one say this is 2 3.
Patient Zero.
This will be the addition button.
This will be the subtraction button and this will be the multiplication button.
And this is the division the division is used to division with a slash.
That's how you identify division in Python.
So you use slash most programming languages actually.
He uses a slash to indicate a division and also of course the equals to button.
So when you do the calculation that you want an equal stop button.
So this is the equals two button here.
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
what's on the screen.
So that is all our buttons that we're going to need for the calculator.
So that's it for this lecture.
Thanks for watching.
Bye for now.