Tkinter的HTML小部件
tk-html-widgets的Python项目详细描述
tku html小部件
Tkinter的HTML小部件
概述
此模块是Tkinter小部件的集合,其文本可以设置为HTML格式。 html小部件不是web浏览器框架,它只是一个简单而轻量级的html解析器,用于格式化tkinter文本基类使用的标记。 小部件的行为类似于pyqt5文本小部件(请参见PyQt5 HTML markup subset)。
安装
pip install tk_html_widgets
要求
- Python 3.4 or later支持tcl/tk
- Pillow 5.3.0
示例
importtkinterastkfromtk_html_widgetsimportHTMLLabelroot=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()
文档
课程:
所有小部件类都继承自tkinter.text()基类。
类htmlscrolledtext(tkinter.text)
Text-box widget with vertical scrollbar
HTMLTEXT类(tkinter.text)
Text-box widget without vertical scrollbar
类htmllabel(tkinter.text)
Text-box widget with label appereance
方法:
定义集合HTML(self,html,strip=true):
Description: Sets the text in HTML format.
Args:
- html: input HTML string
- strip: if True (default) handles spaces in HTML-like style
Def Fit_高度(自身):
Description: Fit widget height in order to display all wrapped lines
HTML支持:
只支持整个html标记和属性的一个子集(见下表)。 如果可能的话,我希望在下一个版本中添加更多的html支持。
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 | local images only |
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 |
比较表
为了检查tku html小部件显示的html文本的外观,我制作了一些html模板,并将html text小部件显示的文本与firefox和pyqt5 qtextbrowser小部件显示的文本进行了比较。 请参阅examples folder中的详细信息和模板html代码。
标签模板比较:
Firefox | tk_html_widgets.HTMLText | PyQt5.QtWidgets.QTextBrowser |
---|---|---|
样式模板比较:
Firefox | tk_html_widgets.HTMLText | PyQt5.QtWidgets.QTextBrowser |
---|---|---|
图像模板比较:
Firefox | tk_html_widgets.HTMLText | PyQt5.QtWidgets.QTextBrowser |
---|---|---|
致谢
感谢我的导师,宝贵的同事和朋友。