Skip to main content

HTML widgets for tkinter

Project description

tk_html_widgets

HTML widgets for tkinter

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 tk_html_widgets

Requirements

Example

import tkinter as tk
from tk_html_widgets import HTMLLabel

root = tk.Tk()
text = HTMLLabel(root)
text.pack(fill="both", expand=True)
text.set_html('<h1 style="color: red; text-align: center"> Hello World </H1>')
text.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 appereance

Methods:

def set_html(self, html, strip=True):

Description: Sets the text in html text.
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 local images only
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

Comparison chart

In order to check the appearance of the HTML text displayed by the tk_html_widgets, I made some HTML templates and I compared the text displayed by the HTMLText widget with the text displayed by Firefox and the PyQt5 QTextBrowser widget. See details and templates HTML code in the examples folder.

Tags template comparison:

Firefox tk_html_widgets.HTMLText PyQt5.QtWidgets.QTextBrowser

Styles template comparison:

Firefox tk_html_widgets.HTMLText PyQt5.QtWidgets.QTextBrowser

Images template comparison:

Firefox tk_html_widgets.HTMLText PyQt5.QtWidgets.QTextBrowser

Acknowledgements

Thanks to my mentor and valued collegue Gianluca: a light in the darkness of code.

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

tk_html_widgets-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

tk_html_widgets-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file tk_html_widgets-0.1.0.tar.gz.

File metadata

  • Download URL: tk_html_widgets-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for tk_html_widgets-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0b5fb4041bb31c0d2f9d8fcdf1cf666101e9cd4e065e8b19f8325e449689b25e
MD5 3d6ed5e7e1d8766035e2b24e2cbd2c98
BLAKE2b-256 06f7e43653e543ae4c5a6dc9090e8a99abd6dea9d9c7cff58e95e40e12814771

See more details on using hashes here.

File details

Details for the file tk_html_widgets-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tk_html_widgets-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for tk_html_widgets-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d31867657b7891b08a5a59f1023f1cea0927780182db37b96549d2b8968a55fb
MD5 25d2c08270b1e149af96e64046528086
BLAKE2b-256 706d699d26911ab33fb654689ad8030dd47b112f3bafbce3f82927e85f9b7d06

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