Convert Tkinter Python App to Executable (.Exe) File [pyinstaller]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome back to my channel in today's video i'm going to show you how you can take a tkinter application that you created using python and convert it into an executable file or a dot exe file the process is very simple and i'm going to go through it step by step in this tutorial the reason you might want to create an exe file or an executable is that maybe you want to share an application that you created with your colleagues or friends or whoever you want and they should be able to run it on their machine with zero issue so consider that you have created this simple login application that you see right here if you want to share it with a friend you will have to ask them to install python install any additional dependencies that you may have in your application figure out how to download the source code and figure out a way to run it so this is a lot to ask of someone especially when you're asking them to set up an application that you created when you create a single executable file you share this single file with them and they should be able to run the application with zero issue with no need to actually install python or any modules they will simply just run this app and they will be able to see it and use it the way you developed it so this is our goal this is what we plan to achieve in this video now i'm using this login form that you see right here this is part of a previous tutorial of mine in which i showed you how to build this using tkinter however i'm not going to go through anything related to the code or how to build it in this video if you're interested you can go to the previous one this is simply reserved for creating the executable file alright so without further ado let's get started i'm going to close this and i'm going to close vs code as well since we no longer need to refer to the code so to create our executable we're going to use a very very popular python library called pi installer this is the most common library used for creating these executable files so pi installer is very simple to install so i'm going to head over to my cmd or my command prompt so as you can see here i'm inside any directory so for the installation process you do not need to be inside the specific directory in which we're going to create this executable for now you can do this from any directory and what you want to do is you want to simply run pip install pi installer so when you do that you will be downloading and installing this library which you will later use to create this executable so let's press enter and wait in my case it says re requirement already satisfied the reason is i already have my installer installed on my machine in your case it's going to take about a minute or two then it gets installed on your machine and you should be ready to go all right so i'm just going to clear this and i'm going to head into the directory of our project so simply i'm going to cd tkinter and not data entry tkinter login form so this is the folder that we want to be in so i've seeded into this directory i actually have it open here in the file exp explorer as well as you can see i just have one file it's the main.pi file this is where all our source code for the login form already exists all right let me pull up the cmd again so now that we have pi installer installed what we want to do is simply convert this pi into an application into a dot exe an executable the way we do this very simple i will simply say pi installer and then main dot pi so here i'm saying go ahead by installer convert main.pi into an application and i press enter so this will take about a minute to convert everything so as i wait for it you can see that some folders are being created here within the file explorer you can see them so when this is done i will show you how we will execute the application okay so now that it's done you can see that multiple files and folders were created so you have this build this list so you have to go actually inside the dist and this is where you'll find the main folder and you're going to find a bunch of different files so you see the one we're actually interested is this one so the main and it's of type application so if i go to properties you can see that it is a dot exe file all right so let's actually try to run it so if i double click on it this should open up the application you can see it opens up a type of command prompt as well or a console and here you have the actual application the login form that i had previously created and of course it should work the exact same way so if i press login it says invalid if i put any user with any maybe incorrect password it should say invalid login as well so as you can see it's definitely working there is this window right here and there are a bunch of files so this is a lot of files to work with now let's say for example i take this main application file and i take it to another folder so let's go ahead and here create a new folder so i'm just going to say let's go with new folder and just create it here so now that i've created it here let me try to run it from inside this new folder what i'm trying to show you guys is that this is what's going to happen when you share this main.exe with your friends or with your colleagues they're going to try to run it on their machines and they're only going to have this one file so now if i try to run it you can see that it crashes the reason is because we have all of these different other files so these files that you can see right here so all of this stuff this is all necessary for the execution of your application so it's not going to run without it now you might be thinking now okay this is so problematic why do i need all of this i don't want to share all of this with my colleagues i just want to share one single file with them and this is very simple to achieve so i'm just going to come back and delete everything we've created so far let's see and only keeping the python file so now going back to the command prompt i'm going to clear and i'm going to go back execute the same thing so pi installer main.pi but this time i will specify a flag called one file by doing so i'm telling pi installer put everything in one single file i don't want to share a million files with my colleagues i want to share one single file and you will see the difference as soon as it is done i'll show you the difference and how you can run it and you can find one file so here we go inside this this time inside this you don't have a folder called main with a bunch of files you have one single file and this is the application so this is what i was trying to tell you that using this one file flag you're able to create only one file for the application let's run it you should see it works the same and let's try to actually move it into a new folder as well so here i'm just going to create a new folder and then let's double click on it and as you can see inside the new folder it also works as well so this is the difference between using the one file flag versus not using it so when you don't use it you're going to end up with a lot of files on your hands however when you use the one file flag you will have only one single dot exe file which you can share and this will be able to run your application so this is much more desirable it's much better because now you're able to consolidate everything into one single file all right so the last thing i want to show you is when we run the application i'm sure you notice this sort of console here gets launched with the application every single time now for someone who doesn't use python this may be very confusing and they may be wondering why it's even here so there is one way to suppress it or to hide it and that's very simple so i'm going to close this and go back let's delete everything that we've done so far okay so now i'm back in my command prompt so again the same exact line so pi installer main dot pi one file except this time i'm going to pass another flag called w this will mean that everything should be inside the one window in our application so this will suppress the additional window which is this console that you're seeing usually reserved for the outputs or print statements of your python program so now when we use this the w flag this should create one file for our application and it should not open up this additional window it should only open up our tkinter application now that it's done i can go to this and here i have the main if i double click on it as you can see it only launches up our application our login form nothing else so this is how we were able to create an executable file from our tkinter application i hope you found this video useful do let me know in the comments if you have any questions and i'll see you in the next one bye bye
Info
Channel: Code First with Hala
Views: 8,128
Rating: undefined out of 5
Keywords:
Id: Iv_dECet_oM
Channel Id: undefined
Length: 9min 10sec (550 seconds)
Published: Fri Sep 16 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.