Skip to content

Andereoo/TkinterWeb

Repository files navigation

PyPi Downloads MIT Licence Python 3 Made in Canada

Buy Me A Coffee

TkinterWeb

Fast and lightweight web browser and app design widgets for Tkinter.

Overview

TkinterWeb offers bindings and extensions to a modified version of the Tkhtml3 widget from http://tkhtml.tcl.tk, which enables enables the display of HTML and CSS code in Tkinter applications.

Some of TkinterWeb's uses include:

  • Displaying websites, feeds, help files, and other styled HTML
  • Displaying images, including SVG images
  • Designing apps using HTML templates
  • Creating prettier apps, with rounded buttons and more!

All major operating systems running Python 3.2+ are supported.

Usage

TkinterWeb provides:

  • A frame widget to display websites, help files, RSS feeds, and any other styled HTML in Tkinter.
  • A label widget that can display styled HTML.
  • A geometry manager to display Tkinter widgets and HTML elements together in a Tkinter application.

TkinterWeb can be used in any Tkinter application to display websites, help pages, documentation, and much more! Here is an example:

import tkinter as tk
from tkinterweb import HtmlFrame # import the HtmlFrame widget

root = tk.Tk() # create the Tkinter window
frame = HtmlFrame(root) # create the HtmlFrame widget
frame.load_website("https://tkinterweb.readthedocs.io/en/latest/index.html") # load a website
frame.pack(fill="both", expand=True) # attach the HtmlFrame widget to the window
root.mainloop()

TkinterWeb

See Getting Started for more tips and tricks.

Installation

To install TkinterWeb, simply type pip install tkinterweb in the command prompt or terminal. That's it!

Or, you can also choose to install optional dependencies:

  • Use pip install tkinterweb[javascript] to also install JavaScript dependencies.
  • Use pip install tkinterweb[svg] to also install Scalable Vector Graphics dependencies.
  • Use pip install tkinterweb[requests] to also install Brotli compression support for faster page loads on some sites.
  • Use pip install tkinterweb[full] to install all optional dependencies.

Dependencies

In order to load webpages and show images, TkinterWeb requires the following packages:

  • Tkinter (which is automatically packaged with most Python installations)
  • TkinterWeb-Tkhtml (can be installed via pip install tkinterweb-tkhtml)
  • PIL (can be installed via pip install pillow)
  • PIL.ImageTk (may be automatically installed with PIL on some systems, otherwise needs to be installed in order to load most image types)

Pip will automatically install PIL and TkinterWeb-Tkhtml when installing TkinterWeb.

API Documentation

Warning

The API changed significantly in version 4.0.0. See Porting to TkinterWeb 4+ for details.

Documentation and additional information on built-in classes can be found in the corresponding API reference pages:

FAQs

See Frequently Asked Questions.

Webpage Compatability

HTML/CSS:

  • TkinterWeb supports HTML 4.01 and CSS 2.1. A full list of supported CSS declarations can be found at http://tkhtml.tcl.tk/support.html.
  • Most CSS pseudo-elements, such as :hover and :active are also supported.
  • On 64-bit Windows and Linux, border-radius and more cursor options are also supported.

JavaScript:

  • Javascript only partly supported at the moment.
    • To use JavaScript, PythonMonkey must be installed.
  • It is also possible for the user to connect their own JavaScript interpreter or manipulate the document through Python.
  • See Using JavaScript for more information and DOM Manipulation with TkinterWeb for information on manipulating the document through Python.

Images:

  • TkinterWeb supports nearly 50 different image types through PIL.
  • In order to load Scalable Vector Graphic images, CairoSVG, both PyCairo and PyGObject, or both PyCairo and Rsvg must also be installed.

Contributing

The best ways to contribute to this project are by submitting a bug report to report bugs or suggest new features, or by submitting a pull request to offer fixes. Your help makes TkinterWeb become more stable and full-featured!

☕ If you’d like to support ongoing development and maintenance, please consider supporting this project by buying me a coffee — any amount is hugely appreciated!

Please check the FAQs and closed bugs before submitting a bug report to see if your question as already been answered.

Credits

TkinterWeb is powered by the Tkhtml project.

Special thanks to Christopher Chavez, Zamy846692, Jośe Fernando Moyano, Bumshakalaka, Trov5, Mark Mayo, Jaedson Silva, Nick Moore, Leonardo Saurwein, and Hbregalad for their code suggestions and pull requests.

Special thanks to Christopher Chavez, Jan Nijtmans, and everyone else in the tcl-core mailing list for the help making border rounding work on Windows and MacOSX, and to Zamy846692 for spearheading experimental Tkhtml development.

Thanks to the TkinterHtml package for providing the bindings on which this project is based, the BRL-CAD project for providing modifications for Tkhtml on 64-bit Windows, and Google Fonts for providing the font used for generating alternative text when images fail to load.

A huge thanks to everyone else who supported this project by reporting bugs and providing suggestions!

About

Widgets for displaying HTML and CSS in Tkinter.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors 7