Skip to content

Widgets for displaying HTML and CSS in Tkinter.

License

Notifications You must be signed in to change notification settings

Andereoo/TkinterWeb

Repository files navigation

Python 3 PyPi Downloads MIT Licence

Buy Me A Coffee

TkinterWeb

A fast and lightweight web browser widget for Tkinter.

Overview

TkinterWeb offers bindings and extensions for the Tkhtml3 widget from http://tkhtml.tcl.tk, which enables displaying HTML and CSS code in Tkinter applications.

All major operating systems running Python 3+ 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("http://tkhtml.tcl.tk/tkhtml.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. Keep in mind these packages may not work on Windows out of the box.
  • 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)
  • PIL (can be installed via pip install pillow)
  • PIL.ImageTk (may be automatically installed with PIL on some systems, otherwise needs to be installed)

Pip will automatically install PIL 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.

JavaScript:

  • Javascript only partly supported at the moment.
    • To use JavaScript, PythonMonkey must be installed.
  • 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 be installed.
  • Without these packages, TkinterWeb will still function properly, but SVG files will not be shown.

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!

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.

Thanks to the TkinterHtml package for providing the bindings on which this project is based.

Thanks to the BRL-CAD project for providing modifications for Tkhtml on 64-bit Windows platforms.

Thanks to Google Fonts for providing the font used for generating alternative text when images fail to load.

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

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