Good what you're seeing here is this creed that we created in the last lecture.
All of this creates a window with a borough's bother and generate came about them which for now do nothing.
But the thing here is that every time we exit this group creepy your window is created.
But also we are creating a point to not the fall because these lines are being executed to what we want
instead to actually execute these lines when we press generate camel bottom.
So the first thing we have to do here is to actually wrap these lines inside of function.
So let's say def K.M. function and here we have to pass two parameters either in file parameter and
an old file parameter we can put some default values to these two parameters.
So the first would be the input file and the second is the food file.
Great.
And of course this parameter needs to reflect the input for the receivers the fall and for the safe
method.
We have an error or even a valid syntax Yes we have and added the column I know to indent all these
lines easily.
You just go ahead to edit and indent.
So we have four function.
Now if I delete this file and exit the script we are just calling.
We do.
So the file is not generated.
So instead we want to call this function when the generator can no bottom be suppressed for that we
need to add a command parameter that will be equal to the name of the function that we want to execute.
That's it.
Now execute the script and say general.
And we have the points for all gyrated
And here to the points.
Let's close this now.
So that's how to have an action to generate Kimbell bottom.
What we also want to do is append function to the borough Bhavan as well.
So that was when the borough's bothered News-Press.
They use there will be performed with a dialog window asking the user to specify those C as the file
that they want to process to create such a dialog.
We know you have to import the as open filename method from Khidir again.
So from Tkinter that file dialogue import ask open file name so a file named method is part of all the
file dialog.
Class of the library.
But before we use ask open file no method I would like you to see what this actually does.
So I'm going to go ahead and or all of this line in the Python console.
And then I create a variable and assigned to the variable.
Then ask open file name execute.
So we have the dialog we do.
Now if we select a file here and say open.
Seemingly not.
Nothing happened but if we print out the file path variable we will get the path of the file that we
selected.
So with the scope of file name is doing that is juried in a string of all the files that we are specifying
either do we window.
So now we have to make use of that and pass that string to all Kimmo function.
So let's go and do just that.
And what we want to do now is to actually spend the over file name method to the Barrow's bottom that
we have created and for that we again have to create a function.
So let's say you've def Burrowes.
And here we say infile equals ask open filename.
Then we want the Broz bottom returns evolved path string.
No we assign the borough's function to the command parameter let's execute the screaming out to see
what's going on but I'll delete the camera for the first and execute.
And so we have two buttons.
So let's test the browes bottom.
Gud looks good.
Let me specify the file I want to convert to K.M. great and then press generate bottom and we get the
points.
Can fall no Everything looks beautiful but it's actually not as beautiful as it looks like it to through
that one.
Prezza generate came the bottom came a function is triggered.
However if you look closely here you'll see that the Kim of function is getting the file impute from
the string.
But this is not what you wanted.
What we wanted was that came a function gets a string out of a Berle's function.
So the Berle's function is the function that generates the file path string.
So what we want to change here is that we want to call the Burleigh's function inside the camera function
this way very turned in fall value will be passed to the infile of peril matter here.
Good.
Well let's execute this now.
Mm hmm.
So he got an open dialog window but we didn't want it to get the dialog window immediately.
We wanted to get it after we bought him.
So why is this happening.
The reason is that we're from exec you just create it from the first line and all the lines one by one
down to the bottom.
And when it goes to the functions it freezes the definition of the functions of a ghost of a claim of
function and what it does here is that it exec used the browse function.
So before we triggering the action by pressing the browser button pythoness executing the browse function
before we pressed Broz bottom.
So we need a way that allows us to grab the infile pass in from the Berle's function but doesn't exec
you the Berle's function.
So the thing that does the trick here is the global variables.
So as I already told you a lecture about the global variables we use a global variable when we don't
want to execute the function.
So we just want to fetch some information on the side of that function.
In such case we don't need the return file here but we just want to make the infile variable obal valuable.
And of course we have to remove the argument here.
So what happens now is that when the script is executed so it reads the definition of the browse function
it reads the definition of a function and it doesn't call any function we need to reach to this definition.
But before we had the brawls function been called a camel function.
So let's take this now and I'll delete the points not the camel file or on we get.
We know very nicely.
I'll go to my computer which for some reason I have renamed to 7 year old who of course you know it's
quick generate and we have a point Scammell file generated areas or African savannah growth so this
is how you create a graphical interface and assign functions to them so that they actually do something.
I'll see you in the next lecture.