|
| 1 | + |
| 2 | +# Briefcase Windows App Template |
| 3 | + |
| 4 | +A |
| 5 | +[Cookiecutter](https://github.com/cookiecutter/cookiecutter/) |
| 6 | +template for building Python apps that will run under Windows, packaged |
| 7 | +as an MSI installer. |
| 8 | + |
| 9 | +## Using this template |
| 10 | + |
| 11 | +The easiest way to use this project is to not use it at all - at least, not |
| 12 | +directly. |
| 13 | +[Briefcase](https://github.com/beeware/briefcase/) |
| 14 | +is a tool that uses this template, rolling it out using data extracted from a |
| 15 | +`pyproject.toml` configuration file. |
| 16 | + |
| 17 | +However, if you *do* want use this template directly... |
| 18 | + |
| 19 | +1. Install [cookiecutter](https://github.com/cookiecutter/cookiecutter). |
| 20 | + This is a tool used to bootstrap complex project templates: |
| 21 | + |
| 22 | + ```text |
| 23 | + pip install cookiecutter |
| 24 | + ``` |
| 25 | +
|
| 26 | +2. Run `cookiecutter` on the template: |
| 27 | +
|
| 28 | + ```text |
| 29 | + cookiecutter https://github.com/beeware/briefcase-windows-app-template |
| 30 | + ``` |
| 31 | +
|
| 32 | + This will ask you for a number of details of your application, including the |
| 33 | + name of your application (which should be a valid PyPI identifier), and |
| 34 | + the Formal Name of your application (the full name you use to describe |
| 35 | + your app). The remainder of these instructions will assume a name of |
| 36 | + `my-project`, and a formal name of `My Project`. |
| 37 | +
|
| 38 | +3. [Obtain a Python Windows Embeddable package](https://github.com/beeware/briefcase-windows-app-template#id1), and extract it into the |
| 39 | + `My Project/src` directory generated by the template. This will give you a |
| 40 | + `python3.dll` (amongst other artefacts) in the `My Project/src` folder. |
| 41 | +
|
| 42 | +4. Add your code to the template, into the `My Project/src/app` directory. |
| 43 | + At the very minimum, you need to have an `app/<app name>/__main__.py` file |
| 44 | + that defines an entry point that will start your application. |
| 45 | +
|
| 46 | + If your code has any dependencies, they should be installed under the |
| 47 | + `My Project/src/app_packages` directory. |
| 48 | +
|
| 49 | +If you've done this correctly, a project with a formal name of `My Project`, |
| 50 | +with an app name of `my-project` should have a directory structure that |
| 51 | +looks something like: |
| 52 | +
|
| 53 | +```text |
| 54 | +My Project/ |
| 55 | + src/ |
| 56 | + app/ |
| 57 | + my_project/ |
| 58 | + __init__.py |
| 59 | + __main__.py |
| 60 | + app.py |
| 61 | + app_packages/ |
| 62 | + ... |
| 63 | + python3.dll |
| 64 | + ... |
| 65 | + briefcase.toml |
| 66 | + my-project.ico |
| 67 | + my-project.wxs |
| 68 | + MyProject.exe |
| 69 | +``` |
| 70 | + |
| 71 | +This project can now be compiled with |
| 72 | +[WiX](https://wixtoolset.org) |
| 73 | +to produce an MSI file. Open a command prompt, and change into the `My Project` |
| 74 | +directory. Then: |
| 75 | + |
| 76 | +```text |
| 77 | +C:\...>wix build -ext WixToolset.UI.wixext -arch x64 my-project.wxs -loc unicode.wxl -o "My Project.msi" |
| 78 | +``` |
| 79 | + |
| 80 | +The MSI file can then be used to install your application. When installed, your |
| 81 | +application will have an entry in your Start menu. |
| 82 | + |
| 83 | +## Next steps |
| 84 | + |
| 85 | +Of course, running Python code isn't very interesting by itself - you won't |
| 86 | +be able to do any console input or output, because a Windows app doesn't |
| 87 | +display a console. |
| 88 | + |
| 89 | +To do something interesting, you'll need to work with the native Windows system |
| 90 | +libraries to draw widgets and respond to screen taps. The |
| 91 | +[Python for .NET](https://pythonnet.github.io/) |
| 92 | +bridging library can be used to interface with the Windows system libraries. |
| 93 | +Alternatively, you could use a cross-platform widget toolkit that supports |
| 94 | +Windows (such as [Toga](https://beeware.org/project/toga/)) to provide a GUI |
| 95 | +for your application. |
| 96 | + |
| 97 | +If you have any external library dependencies (like Toga, or anything other |
| 98 | +third-party library), you should install the library code into the |
| 99 | +`app_packages` directory. This directory is the same as a `site_packages` |
| 100 | +directory on a desktop Python install. |
0 commit comments