Skip to content

Commit a1b697f

Browse files
authored
Runtime icon tutorial (#35)
1 parent 911a596 commit a1b697f

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

docs/en/images/runtime-icon.png

24 KB
Loading

docs/en/tutorial/topics/custom-icons.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ In BeeWare, the term *icon* can refer to two different things:
1010

1111
- **Runtime icons** — Images used inside your app’s interface (for example, in buttons or tables).
1212

13-
This tutorial describes how to set the *application icon*. It will not discuss how to package and use runtime icons.
14-
1513
///
1614

1715
## Adding an icon
@@ -462,3 +460,49 @@ Application 'helloworld' already exists; overwrite [y/N]? y
462460
You can then re-build and re-run the app using `briefcase run`. You won't notice any changes to the desktop app; but the Android or iOS apps should now have a light blue splash screen background.
463461

464462
You'll need to re-create the app like this whenever you make a change to your `pyproject.toml` that doesn't relate to source code or dependencies. Any change to descriptions, version numbers, colors, or permissions will require a re-create step. Because of this, while you are developing your project, you shouldn't make any manual changes to the contents of the `build` folder, and you shouldn't add the `build` folder to your version control system. The `build` folder should be considered entirely ephemeral - an output of the build system that can be recreated as needed to reflect the current configuration of your project.
463+
464+
## Adding a runtime icon
465+
466+
When it comes to adding an icon to the app interface, this type of icon must be stored in a separate directory from the application icons. Right click Tiberius the yak, save that image as a `.png` file and name it `helloworld`. The file should then be saved to the `icons/` folder in your application source package.
467+
468+
![Icon of Tiberius the yak](../../images/runtime-icon.png)
469+
470+
/// caption
471+
472+
///
473+
474+
Your directory will resemble the following:
475+
476+
```text
477+
beeware-tutorial/
478+
├── beeware-venv/
479+
│ └── ...
480+
└── helloworld/
481+
├── ...
482+
├── icons/
483+
│ ├── helloworld.icns
484+
│ ├── helloworld.ico
485+
│ ├── helloworld.png
486+
│ ├── helloworld-16.png
487+
│ └──...
488+
├── src/
489+
│ ├── helloworld
490+
│ │ └── icons/
491+
│ │ └── helloworld.png
492+
│ └──...
493+
└── pyproject.toml
494+
```
495+
496+
Now that the runtime icon is in place, let's add an icon to our button. The Toga button widget will only accommodate either an icon or text (not both), so let's update the code for the button to include the runtime icon.
497+
498+
```python
499+
helloworld_icon = toga.Icon("icons/helloworld")
500+
501+
button = toga.Button(
502+
icon=helloworld_icon,
503+
on_press=self.say_hello,
504+
margin=5,
505+
)
506+
```
507+
508+
Since runtime icons are app resources bundled inside your Python package, no rebuild or resource update is needed. At this point you can run `briefcase dev` (or `briefcase run`) to see the icon added to the button.

0 commit comments

Comments
 (0)