[英]Python: How Can I Render HTML Code And Show The Result To The User?
I'm building a python app that should get a certain HTML code, render it and display the result to the user in a tkinter gui.我正在构建一个 python 应用程序,它应该获取特定的 HTML 代码,呈现它并在 tkinter gui 中向用户显示结果。 How can I do that?我怎样才能做到这一点? I would prefer having some built-in module, or some module which I can use easy_install to get.我更喜欢有一些内置模块,或者一些我可以使用 easy_install 来获取的模块。 Thanks for any advance.感谢您的任何提前。
(I'm using OSX Yosemite with python 2.7) (我将 OSX Yosemite 与 python 2.7 一起使用)
I've managed to render simple html tags using tkhtml我已经设法使用tkhtml呈现简单的 html 标签
just pip3 install tkinterhtml
只需pip3 install tkinterhtml
and, from the package example :并且,从包示例中:
from tkinterhtml import HtmlFrame
import tkinter as tk
root = tk.Tk()
frame = HtmlFrame(root, horizontal_scrollbar="auto")
frame.set_content("<html></html>")
frame.set_content(urllib.request.urlopen("http://thonny.cs.ut.ee").read().decode())
Hope it helps :)希望能帮助到你 :)
Save your HTML to a file location, and use the webbrowser
module's open()
function to display it;将你的 HTML 保存到一个文件位置,并使用webbrowser
模块的open()
函数来显示它; see https://docs.python.org/2/library/webbrowser.html for documentation.有关文档,请参阅https://docs.python.org/2/library/webbrowser.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.