Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tkhtmlview

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tkhtmlview

Display HTML with Tkinter

  • 0.3.1
  • PyPI
  • Socket score

Maintainers
1

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.

TagsAttributesNotes
astyle, href
bstyle
br
codestyle
divstyle
emstyle
h1style
h2style
h3style
h4style
h5style
h6style
istyle
imgsrc, width, heightexperimental support for remote images
listyle
markstyle
olstyle, type1, a, A list types only
pstyle
prestyle
spanstyle
strongstyle
ustyle
ulstylebullet 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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc