Skip to main content

Display HTML with Tkinter

Project description

tkhtmlview

PyPI Publish to Pypi

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

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

FOSSA Status

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tkhtmlview-0.3.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

tkhtmlview-0.3.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file tkhtmlview-0.3.1.tar.gz.

File metadata

  • Download URL: tkhtmlview-0.3.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for tkhtmlview-0.3.1.tar.gz
Algorithm Hash digest
SHA256 6db3ce4a24ab27c50edc10ffe07178f69107cf05187aa44195b30adebafeaab4
MD5 a1f1ec70a6a122d81b7d75719198cc78
BLAKE2b-256 f4f892f9f16d9f4afcd34ece1ab0e21a8276da4b4fc7a7d5fb76ad6ead2809fe

See more details on using hashes here.

File details

Details for the file tkhtmlview-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: tkhtmlview-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for tkhtmlview-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73fdbf8824611e06217fd4e171d4676d7f19c8f0d560342658edcb5253a1d5cf
MD5 d38fa731bd1666b3200689a56d9d1d77
BLAKE2b-256 727cacbcd11d3cbc949ce8f7c4b486ff38444c5bb673ca19095c3e8692fb5559

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page