The HtmlLabel
class is a Tkinter widget that provides HTML parsing abilities to a label-like widget.
It behaves as a Tkinter Label widget, but allows for displaying HTML documents and rich text.
The HtmlLabel widget is very easy to use.
Here is an example:
import tkinter as tk
from tkinterweb import HtmlLabel #import the HtmlLabel widget
root = tk.Tk() #create the Tkinter window
### The important part: create the html widget and attach it to the window
myhtmllabel = HtmlLabel(root, text='<b style="color:blue">Wow! Tkinter Labels can actually show HTML!</b>') # create the label
myhtmllabel.pack() # attach the HtmlLabel widget to the window
root.mainloop()
HTML can also be loaded using the load_html
command to change the content of the label on demand.
master
Parent (tkinter widget)text
Set the content of the widget (string) Default: ""messages_enabled
Enable messages (boolean) Default: False**kw
Other optionalHtmlFrame
arguments
Parses the supplied HTML code.
Parameters
- html_source (string) - Specifies the HTML code
- base_url (string) - Specifies the base url to use when parsing stylesheets and images. If this argument is not supplied, it will be set to the current working directory.
Set TkinterWeb to call the specified python function whenever a link is clicked. When a link is clicked on a webpage, a variable containing the url of the clicked link will be passed to the specified function.
Parameters
- function (python function) - Specifies the function to call when a link is clicked.
Set the zoom multiplier of the document.
Parameters
- multiplier (float or integer) - Specifies the zoom multiplier.
All HtmlFrame methods can also be used on the HtmlLabel widget. For a complete list of avaliable methods, see the HtmlFrame docs.