Hello and welcome to the 3 and the concluding part to the feed you on this project for creatine a weight
conversion tool in this part.
We are going to create the function that will do the calculation.
So we're going to define the function right at the top of the document here.
Edit Or just underneath this module here is where I will define the function.
So we call the function you define it function by typing in the keyword.
Def followed by the name.
So I'm gonna call it calculate
and inside the argument of the function I'm going to pass it this value.
You use this when you're not sure the number of arguments you're gonna pass through.
So this represents the arguments that will pass through that function.
And when you create a function after the parentheses you put a call on there and then now we'll start
to define the logic for the function to save time.
I've added the logic here.
I'm just going to explain what the bot the bunch of code I've added here means.
So here are defined a calculate procedure which is called either when the user presses the calculate
button or hits the return or enter key what it will to do it will perform the feat to meet his calculation
in the number of feet from our Entry widget and placing the result in our label widget we specified
a tax variable options when we created the widget.
So we the we specified that the global fit variable is variable.
Here we define the variable code feet or meters.
We are global.
So here.
So we defined here you see the global feed variable here.
We are using that here as a text variable here is where we define the global feed variables.
We're using that.
We're using that as the N3.
So that's will be where they'll enter the value in Ft.
So which means at any time this entry changes T.K. will automatically update the global variable code
feet.
Similarly if we explicitly change the value of the text variable that is associated with a widget the
widget will automatically be updated with the current contents of the variable.
So we're also doing the same for the meters global variable which is here.
We're so attached to this label here called text variable meta so the same applies to that.
So here also we've implemented some error handling with the try and accept statements.
So whenever you implement error handling you need to implement a try and an accept statement.
So in the try block here we've got the get method which will get the value in Ft.
And here is this is what gets a conversion.
We're using the set method to set the value in meters.
And this is what he does it.
This is how it does a calculation based on this.
So if we multiply this this by the value that is entered and multiply that by this and add this and
divide by that that will give you the conversion in meters.
And here this is any error that occurs it will capture the arrow there.
Okay so that is basically the application.
And here again this is I've already spoken about this but this here is this tells T.K. to enter its
event loop.
This is needed to make everything wrong.
So this is what keeps the application running by the event looping so let me save that and then we can
test and run our application make sure.
Make sure you format your code properly.
If not the editor would complain.
You can see I've got my code structures.
Make sure you've got yours completely structured the same way if not eat or complain someone would click
on save and run the application by going on run and clicking on run module.
Okay.
So this is our application here.
I'm just going to type in a value say see a 56 click calculate.
I can see this is the equivalent in meters.
So the application is working as designed.
So that's it for this project.
Thanks for watching and bye for now.