Python: How Can I Render HTML Code And Show The Result To The User?

余生长醉 提交于 2019-12-24 03:14:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!