tkhtmlview


Nametkhtmlview JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
SummaryDisplay HTML with Tkinter
upload_time2024-03-21 13:20:14
maintainerNone
docs_urlNone
authorPalash Bauri
requires_python<4.0,>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tkhtmlview

![PyPI](https://img.shields.io/pypi/v/tkhtmlview?logo=python&style=flat-square)
[![Publish to Pypi](https://github.com/bauripalash/tkhtmlview/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/bauripalash/tkhtmlview/actions/workflows/publish-to-pypi.yml)

HTML widgets for tkinter

> Fork of [tk_html_widgets](https://github.com/paolo-gurisatti/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](http://doc.qt.io/qt-5/richtext-html-subset.html)).

## Installation

`pip install tkhtmlview`

## Requirements

- [Python 3.6 or later](https://www.python.org/downloads/) with tcl/tk support
- [Pillow 5.3.0](https://github.com/python-pillow/Pillow)
- requests

## Example

```python
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_

    ```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_

    ```python
    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. <br> > **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](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbauripalash%2Ftkhtmlview.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbauripalash%2Ftkhtmlview?ref=badge_large)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tkhtmlview",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Palash Bauri",
    "author_email": "palashbauri1@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fc/31/95ef2458eeb40a6a8b231facbcb862865004057604766ab366c1688aa21e/tkhtmlview-0.3.0.tar.gz",
    "platform": null,
    "description": "# tkhtmlview\n\n![PyPI](https://img.shields.io/pypi/v/tkhtmlview?logo=python&style=flat-square)\n[![Publish to Pypi](https://github.com/bauripalash/tkhtmlview/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/bauripalash/tkhtmlview/actions/workflows/publish-to-pypi.yml)\n\nHTML widgets for tkinter\n\n> Fork of [tk_html_widgets](https://github.com/paolo-gurisatti/tk_html_widgets)\n\n## Overview\n\nThis module is a collection of tkinter widgets whose text can be set in HTML format.\nA 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.\nThe widgets behaviour is similar to the PyQt5 text widgets (see the [PyQt5 HTML markup subset](http://doc.qt.io/qt-5/richtext-html-subset.html)).\n\n## Installation\n\n`pip install tkhtmlview`\n\n## Requirements\n\n- [Python 3.6 or later](https://www.python.org/downloads/) with tcl/tk support\n- [Pillow 5.3.0](https://github.com/python-pillow/Pillow)\n- requests\n\n## Example\n\n```python\nimport tkinter as tk\nfrom tkhtmlview import HTMLLabel\n\nroot = tk.Tk()\nhtml_label = HTMLLabel(root, html='<h1 style=\"color: red; text-align: center\"> Hello World </H1>')\nhtml_label.pack(fill=\"both\", expand=True)\nhtml_label.fit_height()\nroot.mainloop()\n```\n\nYou can also save html in a separate .html file and then use `RenderHTML` to render html for widgets.\n\n- _index.html_\n\n    ```html\n    <!DOCTYPE html>\n    <html>\n        <body>\n            <h1>Orange is so Orange</h1>\n            <img\n            src=\"https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg\"\n            />\n            <p>\n            The orange is the fruit of various citrus species in the family Rutaceae;\n            it primarily refers to Citrus \u00d7 sinensis, which is also called sweet\n            orange, to distinguish it from the related Citrus \u00d7 aurantium, referred to\n            as bitter orange.\n            </p>\n        </body>\n    </html>\n    ```\n\n- _demo.py_\n\n    ```python\n    import tkinter as tk\n    from tkhtmlview import HTMLText, RenderHTML\n\n    root = tk.Tk()\n    html_label = HTMLText(root, html=RenderHTML('index.html'))\n    html_label.pack(fill=\"both\", expand=True)\n    html_label.fit_height()\n    root.mainloop()\n    ```\n\n## Documentation\n\n### Classes\n\nAll widget classes inherits from the tkinter.Text() base class.\n\n#### class HTMLScrolledText(tkinter.Text)\n\n> Text-box widget with vertical scrollbar\n\n#### class HTMLText(tkinter.Text)\n\n> Text-box widget without vertical scrollbar\n\n#### class HTMLLabel(tkinter.Text)\n\n> Text-box widget with label appearance\n\n#### class RenderHTML\n\n> RenderHTML class will render HTML from .html file for the widgets.\n\n### Methods\n\n#### def set_html(self, html, strip=True)\n\n> **Description:** Sets the text in HTML format. <br> > **Args:**\n>\n> - _html_: input HTML string\n> - _strip_: if True (default) handles spaces in HTML-like style\n\n#### def fit_height(self)\n\n> **Description:** Fit widget height in order to display all wrapped lines\n\n### HTML support\n\nOnly a subset of the whole HTML tags and attributes are supported (see table below).\nWhere is possibile, I hope to add more HTML support in the next releases.\n\n| **Tags** | **Attributes**     | **Notes**                              |\n| -------- | ------------------ | -------------------------------------- |\n| a        | style, href        |\n| b        | style              |\n| br       |                    |\n| code     | style              |\n| div      | style              |\n| em       | style              |\n| h1       | style              |\n| h2       | style              |\n| h3       | style              |\n| h4       | style              |\n| h5       | style              |\n| h6       | style              |\n| i        | style              |\n| img      | src, width, height | experimental support for remote images |\n| li       | style              |\n| mark     | style              |\n| ol       | style, type        | 1, a, A list types only                |\n| p        | style              |\n| pre      | style              |\n| span     | style              |\n| strong   | style              |\n| u        | style              |\n| ul       | style              | bullet glyphs only                     |\n| table,tr,th,td | - | basic support|\n\n> Note: All styles are not supported;\n> align with justify is not supported; it falls back to left align\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbauripalash%2Ftkhtmlview.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbauripalash%2Ftkhtmlview?ref=badge_large)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Display HTML with Tkinter",
    "version": "0.3.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "012053664ac695fa4ec80aa96504025b1c8013cf201fac5ba04e40df71c9ea4d",
                "md5": "c9d8d3a5a4bbc63469ab1d8f857bcd24",
                "sha256": "e01e8c729c876eaedcba91cb8a2eb2189d260fad0c051452d9b794335eee61bd"
            },
            "downloads": -1,
            "filename": "tkhtmlview-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c9d8d3a5a4bbc63469ab1d8f857bcd24",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 10557,
            "upload_time": "2024-03-21T13:20:12",
            "upload_time_iso_8601": "2024-03-21T13:20:12.019463Z",
            "url": "https://files.pythonhosted.org/packages/01/20/53664ac695fa4ec80aa96504025b1c8013cf201fac5ba04e40df71c9ea4d/tkhtmlview-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc3195ef2458eeb40a6a8b231facbcb862865004057604766ab366c1688aa21e",
                "md5": "67d7856d9f2d12349465a544bcde15e2",
                "sha256": "7b3599971ed3311ccff41633f8e152931362f7c6c79ce7f2f5b62a4480383381"
            },
            "downloads": -1,
            "filename": "tkhtmlview-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "67d7856d9f2d12349465a544bcde15e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 11172,
            "upload_time": "2024-03-21T13:20:14",
            "upload_time_iso_8601": "2024-03-21T13:20:14.071210Z",
            "url": "https://files.pythonhosted.org/packages/fc/31/95ef2458eeb40a6a8b231facbcb862865004057604766ab366c1688aa21e/tkhtmlview-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-21 13:20:14",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "tkhtmlview"
}
        
Elapsed time: 0.29537s