Monday, September 7, 2015

Learn Quickly Creating Professional Looking Desktop Application Using Python - Part 7 of 7

Compiling, Packaging and Distributing Our Completed App

Quick links to other parts of this blog series:
Part-1 | Part-2 | Part-3 | Part-4 | Part-5 | Part-6 | Part-7

Am glad you read this far, we are almost there!
For sure, we can zip the “gui.py” file and distribute it by emails or other means. But the problem with this is that only users with Python and wxPython lib installed on their PC can run the application (so we have a BIG drawback here).

The primary aim of today's class is to take our application to the next level by making it possible for every computer system to run it with or without Python installed on it. To achieve this, we make use of two programs we have installed earlier (i.e. Py2exe and Inno Setup Compiler).

~~ First we use the "Py2exe" python library to create an executable for our application, then we use "Inno Setup Compiler" to create an installer for our app.

~~ Now create a blank file name “setup.py” and type this code below in it and save.

from distutils.core import setup
import py2exe

setup(windows=['gui.py'])
~~ Run the following on the command prompt to create an executable for our app.
python setup.py py2exe


This will run and generate to folders named “build” and “dist” in our project folder. Open the “dist” folder, the app executable will be seen there and the “build” folder is no longer essential. See image-27 below.

~~ Contents of your “dist” folder should look like mine below (image-28); the executable file is shown with arrow (that is: gui.exe).
Double clicking the executable file (gui.exe) should open up the Expression Evaluator Application, BOOM!

~~ Now we can rename the “dist” folder to the name of our app (Expression Evaluator) and zip it for distribution. Any windows PC would be able to run our Expression Evaluator application with or without Python/wxPython library installed on the computer.

To add more professionalism to our program, we will compile it into an installer using the Inno Setup Compiler.

~~ Launch the Inno Setup Compiler and chose “create a new script file using wizard” and click “Ok”. See image-29.

~~ On the next couple of screens press “Next” and fill the appropriate details.

~~ On the “Application file” page, click “Browse” then navigate to the “dist” folder and select the executable file (gui.exe). See image-30

~~ Click on “Add files” button to add all the files within the “dist” folder. See image-31

~~ On the next window chose option that suite your needs. I will accept default options and go to next page “Application documentation” then select your setup language(s).

~~ On the “Compiler settings” window, you can select an icon for the installer setup file and you can also set password for the installer.
Select “Yes” when you see the screen (See image-32) below to compile instantly.

~~ Save your script and inno setup compiler does its thing... This script can be edited using Pascal programming language. See image-33


~~ When it finishes, go to the folder you selected for the setup output to see the installer created by inno setup compiler placed in a folder named “output”. See image-34

~~ This setup can now be distributed for installation on window PCs that doesn’t have python installed.
Our application is now more professional. We can run the installer to install the Expression evaluator program on any computer system.

~~ After installing it, check the windows start panel, or desktop (if you enabled this option) to see your installed app as show below (image-35). An icon to the software will also be available in the system’s control panel for un-installation. See image-36.

This mark the end to this tutorial, hope you enjoyed reading it?
Be free to share and ask questions















Conclusion

Over the past few days, you have learned how to create a simple but useful application with wxPython.

We’ve now created a useful application with limited knowledge of wxPython. The simplicity of it all proves how easy it is to create graphical user interfaces in Python applications by using the wxPython library. In fact, the most complicated thing we did in the whole application was create a system that would allow us to easily perform operations and make our calculator work.

Here are the python files containing codes generated through the tutorial. That is:-
1) eval.py = the console version of the Expression Evaluator
2) frame.py = our first frame/window in wxpython
3) gui.py = the GUI code
4) setup.py = the code that creates .exe file

There’s still a lot more to wxPython.

Happy wxPython GUI coding

No comments:

Post a Comment