tkhtmlview
HTML widgets for tkinter
Fork of tk_html_widgets
Overview
This module is a collection of tkinter widgets whose text can be set in HTML format. A HTML widget isn't a web browser frame, it's only a simple and lightweight HTML parser that formats the tags used by the tkinter Text base class. The widgets behaviour is similar to the PyQt5 text widgets (see the PyQt5 HTML markup subset).
Installation
pip install tkhtmlview
Requirements
- Python 3.10 or later with tcl/tk support
- Pillow 11 or later
- requests
Example
import tkinter as tk
from tkhtmlview import HTMLLabel
root = tk.Tk()
html_label = HTMLLabel(root, html='<h1 style="color: red; text-align: center"> Hello World </H1>')
html_label.pack(fill="both", expand=True)
html_label.fit_height()
root.mainloop()
You can also save html in a separate .html file and then use RenderHTML to render html for widgets.
-
index.html
<!DOCTYPE html> <html> <body> <h1>Orange is so Orange</h1> <img src="https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg" /> <p> The orange is the fruit of various citrus species in the family Rutaceae; it primarily refers to Citrus × sinensis, which is also called sweet orange, to distinguish it from the related Citrus × aurantium, referred to as bitter orange. </p> </body> </html>
-
demo.py
import tkinter as tk from tkhtmlview import HTMLText, RenderHTML root = tk.Tk() html_label = HTMLText(root, html=RenderHTML('index.html')) html_label.pack(fill="both", expand=True) html_label.fit_height() root.mainloop()
Documentation
Classes
All widget classes inherits from the tkinter.Text() base class.
class HTMLScrolledText(tkinter.Text)
Text-box widget with vertical scrollbar
class HTMLText(tkinter.Text)
Text-box widget without vertical scrollbar
class HTMLLabel(tkinter.Text)
Text-box widget with label appearance
class RenderHTML
RenderHTML class will render HTML from .html file for the widgets.
Methods
def set_html(self, html, strip=True)
Description: Sets the text in HTML format.
> Args:
- html: input HTML string
- strip: if True (default) handles spaces in HTML-like style
def fit_height(self)
Description: Fit widget height in order to display all wrapped lines
HTML support
Only a subset of the whole HTML tags and attributes are supported (see table below). Where is possibile, I hope to add more HTML support in the next releases.
| Tags | Attributes | Notes |
|---|---|---|
| a | style, href | |
| b | style | |
| br | ||
| code | style | |
| div | style | |
| em | style | |
| h1 | style | |
| h2 | style | |
| h3 | style | |
| h4 | style | |
| h5 | style | |
| h6 | style | |
| i | style | |
| img | src, width, height | experimental support for remote images |
| li | style | |
| mark | style | |
| ol | style, type | 1, a, A list types only |
| p | style | |
| pre | style | |
| span | style | |
| strong | style | |
| u | style | |
| ul | style | bullet glyphs only |
| table,tr,th,td | - | basic support |
Note: All styles are not supported; align with justify is not supported; it falls back to left align
License
Metadata
Release files for tkhtmlview 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tkhtmlview-0.3.2.tar.gz | 8.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tkhtmlview-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.7 kB
Release files / tkhtmlview-0.3.2.tar.gz
| Download URL | tkhtmlview-0.3.2.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9f34def321585407a19b40a69c63cffa4e4acadff1ccf8b81a4e27afc9bace0
|
|
BLAKE2b-256 checksum How to use checksums |
75177e8acc5bf815f7be9639a5ffc5eaafbb7f9a3c2e6cfcc8114c7397aba9d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / tkhtmlview-0.3.2-py3-none-any.whl
| Download URL | tkhtmlview-0.3.2-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21f4492e98e3800a7ef5db223d201430aff3d855cf1dab3e40f17c1acc2e6739
|
|
BLAKE2b-256 checksum How to use checksums |
4da24b53d0d9a5eca110c774f4f3921c166f8fd4ca952f5f6b2a1d680a1a9b2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for tkhtmlview 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.