Hey, welcome back.
By the end of this video.
You will have learned how to create this graphical user interface.
This has four elements.
First, it is the window which contains everything, the window element.
Then it contains this label which writes type in A to do.
Then it contains this input text box and then it contains this button.
So you will learn how to create all these four elements the window, the label, the input box and the
button.
Let's begin.
This year is the command line interface, the code base of the command line interface.
What I'm going to do now.
Is.
I'm going to rename this.
By going to refactor and going to rename to something else.
Such as?
C l i which stands for command line interface.
You can put whatever name you want, but I would suggest not to keep the name main that P.
We generally use main p y when we only have one front end and we know that main that p y is the entry
points of our app.
So that's the script we actually execute with Python.
So we don't execute functions that p y, we execute it main that P But now since we are developing more
than one interface, I want to keep this as it is, give it a more meaningful name and then create a
new python file and call it gooey.
That's pie.
Although even if you don't type that pie in pie chart, pie chart will add that pie by default.
Now, as soon as I created that gooey, that pie file, I got this window popping up.
This window shows up.
If you have enabled get in your project in your patch on project.
And I showed you how to do that.
Yesterday in the yesterday's programming to video where I covered Git.
So in that case you want to press add and that will add gooey pie in the list of versioned files.
So git is going to keep track of this file if we press add here.
So press add.
All right, let's continue coding.
So now we have an empty, gooey dot p y file.
And here is where we're going to write the graphical user interface.
First of all, we want to import functions because we're going to need these two functions in this gooey
as well.
Then what type can we use to create a window, a text box, a label, and a button?
So is there in Python something like a window?
Type or a button type.
You know, like we have a list type, but no button type or window type.
So these kinds of objects, they don't exist by default in Python.
They are not included.
Python does have a standard module called Enter or Tick enter.
So that's a standard library, but I would prefer to use a more advanced library.
And this advanced library is made available as a third party module or library.
The word module and library are used interchangeably.
So I introduced you to standard modules previously yesterday, and you can also refer to those modules
as standard libraries.
The same, we can say, for third party libraries, third party modules.
So what are third party modules or libraries?
Well, these are Python files, which are the people have created.
And we can get those Python files and use the functions written in those Python files.
So somebody else created functions which generate these window types and button types.
And we can just use this to create instances of those buttons, instances of those text boxes, instances
of those windows.
A complete list of Python third party libraries can be found on p y.
P i dot org.
So that is a repository where everyone can create such libraries and they can upload them to these sites
and everyone then can use these Python libraries.
I'll show you how to use them.
For example, if I search here for P one simple gooey and I press enter.
This first results p y simple gooey is the library we're going to use to create our graphical user interface.
So the Python files of this library contain those special types, the buttons, the window, etc..
If I click over here, it's going to take me to the home page of this library.
And up here you see this PIP install p y symbol.
That is the command that copies all the python files of this library and puts them on your computer.
So then you can use those types.
So therefore, I want to copy this.
Go to Pi charm, and then I'll show you two different ways to install packages.
The first way, which I do recommend you to use, especially if you are using Parcham, is to go to
Parcham and then to preferences or settings.
Wherever it shows here.
And then go to.
Project.
That's the name of my project.
Expanded.
Go to Python interpreter.
And down here you will see the list of third party Python libraries.
Now, these are by default included, but you can add more using this plus icon.
And here you want to search for P?
Why?
Simple gooey.
It's one word no spaces and install that package.
So there are different packages with different names you want to install p y symbol.
Go with that one by pressing on this install package button.
Present.
I see this progress bar here, so my package is installing.
That means the python files are now being downloaded from the online repository where the person who
developed this package posted the files.
And so these files are being downloaded and copied to my Python installation directory.
Now, usually people will upload the files, the library files to GitHub.
So actually Parcham now is downloading those files from GitHub.
And if we see here, we see the actual link to the GitHub page.
So if I click that link.
It's going to show all the folders and the Python files.
For example, we have this underscore underscore, init, underscore dot pi.
We have this other dot pie file.
And these folders also might have dot P files.
Now, you don't actually need to look inside these files, so all you have to do is actually import
this package.
Let me show you how to do that.
So package P was simple to install successfully, so now I can close this window.
Press okay, here or exit whatever, and then import p Y with capital P simple with capital S gooey
with capital letters.
And that's how you import the module, the library.
So just like we do with functions, that's pi.
We also do this with this library, which is also a python file.
So if I right click here and go to go to and implementations, we're going to see that this is actually
a python file.
It's called underscore, underscore in it underscore, underscore.
It's a spatial name used for libraries and it tells.
Also that's this file is importing other python files from other places.
So there are multiple python files which basically import each other.
So these are details that we don't need to worry about for now.
All you need to know is that these are Python files, and these files contain some types which we're
going to use to create instances.
So that was one way to install the package.
Another way is to go to the terminal.
And here you want to type in pip install.
P.
Simple.
Good.
So that is the command that we saw in the home page of the library that went in there.
So what is Pip?
Pip is also a third party library for Python.
And Pip is used to install other third party libraries, so it's available in the command line.
Now, don't confuse the terminal with the python console.
So Pip is used in the terminal, not in the python console.
If you write pip here and execute, you're going to get an error, a python error.
So go to the terminal and do that.
Press enter.
And if you get this, that means Pip is not recognized by your computer.
That is mostly the case when you have different Python installations on your computer.
In that case, you will have to press the upper arrow key to call that command again, then go with
the left arrow key to PIP and write three.
So we want to try pip free install py simple and then press enter.
And the package will start to install.
Now you only have to do this if the other installation method didn't work for you.
So if this method.
Through the graphical installer didn't work.
But I still wanted to demonstrate this method in case you are on another IDE other than porch form.
Now, once you do this try to import possible gooey.
So if you try to execute with right click and run gooey, if you don't get an error, that means pie.
Simple gooey was installed successfully.
If you get an error such as.
The module was not found.
That means by simple Google was not installed in that case.
Go to the terminal and try other commands such as PIP 3.10.
If you have Python 3.10.
If you have Python 3.11, write pip 3.11.
So no space is between pip and three or pip 3.12, depending on what version you have.
And then press enter again and then try to import and run the script again until you don't get an error
here.
So in my case, P was simple.
Gooey was installed successfully.
I can go ahead and create an instance of a window type.
So just like we have the list type and we create instances of that list using that syntax in here we
have something.
Called.
Window.
So that is a type just like list is a type.
This is also a type.
Sorry, this has to be quite simple, gooey.
So this is a type and it has to be associated with P simple gooey, because it's located inside those
files.
It's not a built in type which we can access directly without any dots.
I hope that is clear.
Now, this is the type, but what is the instance?
The instance in the case of a list is that in the case of a string type, it is something in quotes,
right?
That is an instance of a string type, an instance of a window type as this in parentheses.
And here you insert the values that window gets.
So this looks like a function called, but it's not a function actually.
Indeed, this is actually a capital W, So sorry for that.
This is uppercase W And now inside this parentheses you can place a string.
You can say my two.
Do app, for example, and this will be the title of the window.
So just like the lists have these values, so these are the components of the list instance.
This is the content of the string instance.
This is also.
An element of that instance.
You know, I love the cafe analogy to explain your types and Python elements, so I'm going to talk
about that again.
Let's say in the cafe you order a pizza.
The problem is the cafe only makes coffee instances and tea instances and things like that.
They don't make pizzas.
However, they offer this service that they order the pizza for you from a third party, so they order
it from a pizza shop nearby.
The same is happening here.
Python doesn't have window objects by default or both, so we can get those object instances from other
third parties.
So Python doesn't have everything because it would become very happy.
The same goes for that coffee.
It would become a mess if they had everything.
So it's better for some things to get them from third parties.
So the pie is simple gooey port.
Here is the pizza shop and the window open parenthesis.
My to do app close parentheses that is the actual pizza instance.
And you could say that my to do app that part is what pizza you want so CAPRICCIOSO or quatro for Margie
or cinco for Margie whatever pizza that is in our case this is just the title of the window instance.
I hope that makes some sense.
Now this window type also needs some other.
Elements.
It needs a layout, which for now I'm going to just put it an empty string and that's it.
So that is an instance, but currently it doesn't have a variable associated with itself.
So I'm going to create a variable here, call it window or other name, whatever you like.
And so that instance now is stored in this variable.
Then you use the read method of that instance.
So just like strings and lists have their methods such as tests that.
Capitalize.
You get that?
This method, what it does is it displays the window actually on the screen, because when you create
a string, you just create the string instance, right?
It's somewhere in the memory.
But when you print it with this function, then it displays in the command line.
So for this as well, we have a read method.
It's not a function, it's a method associated to this instance.
Then once you display the window, you then you want to close it with window.
That close another method right click and run.
Now this error, if you go up, you want to read the error from top to bottom.
So here the first line tells you where the error originated.
So in line five, that means when the interpreter went to this line, it tried to call this method read,
but then the method.
If you see down here.
The method is defined somewhere, just like a function is defined.
So if I click here, it's going to take me actually to where the method is being used by the files of
this library.
We don't need to look at this, actually.
As I told you, these are implementations, details of the library itself.
So we don't need to change anything here.
But I wanted to show you that there is a chain of errors that happens in that library because we did
something wrong and we can read the details in here.
It says Value error.
Max is an empty sequence.
Now, this error is not so well described by the authors of this library.
They could have done better.
So this is one of the hard to solve errors because it doesn't give us much information.
The only clue here is that this is a sequence, and I know from experience that this layout arguments
so types also have arguments just like functions do.
But I'm going to talk about that.
When you learn about types and classes later on in the course.
So this layout has to be a list.
Lists are sequences.
So let's run again.
Again, this says that this is an empty sequence.
So this sequence has to has something inside.
So let's put an empty string there.
Run again.
And now no errors.
And if you're able to see this is the window we created.
It has this close button and that's it.
So let me close this window and let's add some elements to this.
I'm going to create a label element which is equal to P.
Why?
Simple gooey dot.
Text.
So text type.
Now we had an end window type that created that small window.
Now we have a text type which creates a label on the window.
So it's not a string.
A string is something that is displayed in a command line interface.
This is something else, and this now needs an input.
The input is a string instance type in A to do.
We have this like I and made of.
Other items.
For example, we can have a list of.
Strings.
Hey, and so on.
The same goes here.
This text instance can have also strings.
The only difference here is that this has to be a string.
So four lists, lists can have anything, but this has to be string here so that it's a label.
Let's create.
An input box as well, which is equal to p simple gooey dot.
Now, since we are using this possible gooey name over and over again and this is hard to type, we
could do something.
We could say import p simple gooey as as g.
And now this name represents that name.
That means we can replace this with as G and this with as G and this with Z G as well.
And things will work exactly the same.
So now as g dot input text.
And this can be empty.
You don't need to put any arguments there, but if you like, you can say tooltip.
Is equal to answer to do and let's execute.
So run.
Going.
And we still see the same window because now we created these instances, but they are floating somewhere.
We haven't connected them to the window.
For instance.
So the window instance has to be aware of these.
So let's make the window instance aware of these two instances.
To do that, you want to go to layout.
And put the label there and the input box as well.
And these two have to go inside another set of.
Square brackets.
I'll explain why.
But first, let's right click and run the program.
And this is what we've got this time.
So that's the title My to Do app, which reflects the title of the Window instance.
And then we have typing a to do.
So that is a label which reflects the text instance.
And that is the text box.
If I over the mouse, I see this enter to to label, which is the tooltip.
So if you see among your programs, you see this Python program that is actually the graphical user
interface, the actual program, which has a graphical user interface.
So this is a program we generated.
Now about this syntax here, layout is equal to square bracket square brackets.
So layout expects a list.
Layout is an argument and it expects a list.
And this will be a list of object instances.
Buttons.
Text boxes.
So first we have the outer square brackets, right?
And then we have.
Inner screw brackets.
Now, the items you put inside this inner screw brackets will be placed in one row.
You see, the label is here and on the right we see the input box.
So if I wanted to put the input box below typing a to do, I would do this.
I would put the label inside square brackets alone and then the input box inside square brackets also
alone.
On itself.
So that means now we're going to have one row here and one row in here.
So first, go to the program, close it, and then rerun it.
You see, typing a to do is here and then the input text is below that label.
Let's add a button.
So I'm going to name this add button.
This is going to be the button which adds to do.
We're going to have more buttons later, such as the edit button, the complete button.
Therefore, I'm going to use different variable names for each one as dot button.
This is also an instance which is created by the button type.
Give a label to the button such as and check to see if the program is running.
No, it's not.
So I'm going to run.
Sometimes it doesn't show.
So in that case, you want to click over.
The program in the list of your open programs and quit it there, perhaps, and then run again.
So now it's working.
Oh, but I forgot to add that add button variable in here.
So where do I want to add that button?
Do I add it in the same row with label?
If that is the case, that would be like that.
Run and button.
The button is here on the side.
But it makes more sense.
To remove it from here and put it on the side of the input box.
So go to the program.
Close it.
Run again.
Very good.
No, you ask, what if we press that button?
Nothing is going to happen except of the program being closed.
So nothing is happening because we haven't connected this button to any actions.
We want to connect it to some functions and we'll do that in the next video.
So to wrap it up, what we did in this video was we created some instances of different types in here,
and then we created an instance of a window as well, which basically is the parent of all these instances.
So this mother instance contains those other objects, and that is possible through this layout argument
which we see in here.
So Layout expects a list, a list of lists, and each of those lists contains par simple instances.
So a list is not just.
A sequence of numbers or strings.
Lists can contain everything.
So that is a python list and it contains lists of possible key object instances.
And then here, once we create those objects, then we want to display them.
So this method displays them, and then this closed method closes.
The program when we press some buttons.
So, for example, if I print here.
Hello.
And I run the program.
You're going to see that hello is not printed out in here.
That means the interpreter has.
Executed the program up to here.
But then here it holds it suspends the execution.
I need to wait for user action.
So if you press anything now, this button or that button, then the interpreter will go on and go past
this method and it will execute the next lines, the rest of the lines.
So let's try that.
Let me close the window.
Yeah, you see that?
Hello?
Now it's printed out.
So that was what I wanted to show you with this print function, that I wanted to prove you that the
code is initially executed up to here, and that is going to be useful in the next videos when we add
some interaction to this button, the add button.
And now, before I close the video, I want to commit my changes using this git commit button.
So press that sealed that pie and go that pie are going to be selected.
So select them if they are not selected by default and we want to write a commit message.
Such as create basic gooey without interactions and also add.
D 16.
Just a note since we are in this course, so it helps us keep track of the days as well.
So why am I committing this point?
Well, because I think this is a milestone.
So I commit now and later, if I want to go back to this milestone, I can.
So it allows me to see the code as it was at this point.
Tomorrow, we're going to develop the code even more.
We're going to create a new commit, etc..
So finally, I'll press commit.
And I've got this message.
The commit was successful, so I'm done for the day.
I call it a day.
And thank you for following and see you later.