A library to draw MDI icons onto PIL Image objects.
Project description
MDI PIL
This is a small library made to easily generate PIL Image objects of mdi
(Material Design Icon) icons. It also comes with a tool to convert user supplied image files into image objects that adhere to the main sizing principles of mdi icons.
There are also two additional functions, parse_weather_icon and make_battery_icon. The former returns a string with the mdi icon corresponding to a given weather condition. The latter creates an image that is similar to the icon showing the battery status in phones, with additional options like fill icons and the like. See the doc strings of those functions for how they work.
To see a project using both implementations, check out inkBoard Designer. It uses PythonScreenStackManager for the actual dashboards (which is what this module was originally written for), and the UI makes heavy use of the ttkbootstrap module (and it is also where the idea for that module was born).
Install
pip install mdi-pil
Examples
Make a PIL image object with the icon "mdi:test-tube" and open a window to show it:
from PIL import Image
import mdi_pil as mdi
icon = "mdi:test-tube"
img = Image.new("RGBA", (100,100), None)
img = mdi.draw_mdi_icon(img, icon, icon_color="steelblue")
img.show()
Convert the image file "speaker-outline.png" into an mdi-like icon:
from PIL import Image
import mdi_pil as mdi
img = "speaker-outline.png"
img = mdi.make_mdi_icon(img, 100, color="steelblue")
img.show()
ttkbootstrap
Version 1.1.0 comes with an optional extension to use MDI icons in tkinter interfaces. To have functional theming, the ttkbootstrap package is used.
installation: pip install mdi-pil[ttkbootstrap] (If ttkbootstrap is not yet installed)
Usage:
The classes return PhotoImage objects, so they are used in the same way you'd use a PIL.ImageTk.PhotoImage.
For more info on styling than is in the docstrings, look at the documentation for ttkbootstrap and tkinter itself.
A very rudimentary example is below, which can be run as is:
from ttkbootstrap import Window, Button
from mdi_pil.ttkbootstrap_mdi import MDIIcon, MDIButton
window_size = (750,200)
root = Window(size=window_size)
KEEP = [] ##Images need to be saved somewhere to prevent garbage collecion
icon = "mdi:test-tube"
icon_size = int(window_size[1]/2)
imgTk = MDIIcon(icon, (100,100), bootstyle="info")
iconWidget = Button(root,image=imgTk, cursor="hand2",
width=100, padding=-1
)
KEEP.append(imgTk)
iconWidget.pack()
icon = "mdi:earth"
text = "Hello World!"
button_size = (window_size[0],int(window_size[1]/2))
imgTk = MDIButton(icon, text, button_size, bootstyle="success")
buttonWidget = Button(root,image=imgTk, cursor="hand2")
KEEP.append(imgTk)
buttonWidget.pack()
root.mainloop()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdi_pil-1.1.7.tar.gz.
File metadata
- Download URL: mdi_pil-1.1.7.tar.gz
- Upload date:
- Size: 688.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b12a83a269a6ada4368e39a0c2cd6ec2e5a315d28f1aa749055a02baa488d1b7
|
|
| MD5 |
ea03c28f25b2c74520a1b1539a34af48
|
|
| BLAKE2b-256 |
4ac76a495805f1d1ede47af7bad4eeecdd480b77ff7672a891587d45c3213552
|
Provenance
The following attestation bundles were made for mdi_pil-1.1.7.tar.gz:
Publisher:
publish.yml on Slalamander/mdi_pil
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdi_pil-1.1.7.tar.gz -
Subject digest:
b12a83a269a6ada4368e39a0c2cd6ec2e5a315d28f1aa749055a02baa488d1b7 - Sigstore transparency entry: 161096129
- Sigstore integration time:
-
Permalink:
Slalamander/mdi_pil@dfb16ae4e3546675654c4c81e73eb6a846bc0766 -
Branch / Tag:
refs/tags/v1.1.7 - Owner: https://github.com/Slalamander
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dfb16ae4e3546675654c4c81e73eb6a846bc0766 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mdi_pil-1.1.7-py3-none-any.whl.
File metadata
- Download URL: mdi_pil-1.1.7-py3-none-any.whl
- Upload date:
- Size: 676.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76baa6004cf1de6ff2c801f622ed30ea0938b1fbe1f0a64d1d8481cdf702c628
|
|
| MD5 |
1c56ff4a55a617ce74eebb39d8b45a66
|
|
| BLAKE2b-256 |
3ae29555f39f14fa9ee9abffc6cb563aa9cd6afbf7570dddf466a8c29c1ec23f
|
Provenance
The following attestation bundles were made for mdi_pil-1.1.7-py3-none-any.whl:
Publisher:
publish.yml on Slalamander/mdi_pil
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mdi_pil-1.1.7-py3-none-any.whl -
Subject digest:
76baa6004cf1de6ff2c801f622ed30ea0938b1fbe1f0a64d1d8481cdf702c628 - Sigstore transparency entry: 161096131
- Sigstore integration time:
-
Permalink:
Slalamander/mdi_pil@dfb16ae4e3546675654c4c81e73eb6a846bc0766 -
Branch / Tag:
refs/tags/v1.1.7 - Owner: https://github.com/Slalamander
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dfb16ae4e3546675654c4c81e73eb6a846bc0766 -
Trigger Event:
release
-
Statement type: