问题
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. How can I do that? I would prefer having some built-in module, or some module which I can use easy_install to get. Thanks for any advance.
(I'm using OSX Yosemite with python 2.7)
回答1:
I've managed to render simple html tags using tkhtml
just pip3 install tkinterhtml
and, from the package example:
from tkinterhtml import HtmlFrame
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 :)
回答2:
Save your HTML to a file location, and use the webbrowser
module's open()
function to display it; see https://docs.python.org/2/library/webbrowser.html for documentation.
来源:https://stackoverflow.com/questions/29908340/python-how-can-i-render-html-code-and-show-the-result-to-the-user