A fast and lightweight web browser widget for Tkinter.
TkinterWeb offers bindings 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.
TkinterWeb provides:
- A frame widget to display websites, help files, 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. 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()
Some other tricks, such as handling page title changes, link clicks, and navigation key presses, can be found in the HtmlFrame documentation.
To install TkinterWeb, simply type pip install tkinterweb
in the command prompt or terminal.
That's it.
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.
TkinterWeb ships with a few classes that make it quick and easy to use.
Documentation and additional information for these classes can be found in the corresponding API refrence pages:
See https://github.com/Andereoo/TkinterWeb/blob/main/docs/FAQ.md.
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 is not supported at the moment, but it is possible to manipulate the document through Python. See DOM Manipulation with TkinterWeb.
Images:
- TkinterWeb supports nearly 50 different image types through PIL. However, in order to load Scalable Vector Graphic images:
- PyCairo or PyGObject must be installed.
- Either Rsvg, PyGObject, or CairoSVG must also be installed.
- Without these packages, TkinterWeb will still function properly, but SVG files will not be shown.
TkinterWeb happily accepts contributions.
The best way to contribute to this project is to go to the issues tab and report bugs or submit a feature request. This helps 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.
TkinterWeb is powered by the Tkhtml project.
Thanks to the TkinterHtml package for providing the bindings which this project is based on.
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 alternate text when images fail to load.
A special thanks to everyone else who helped this project by reporting bugs, creating pull requests, and providing suggestions!