简体   繁体   English

Python:如何呈现 HTML 代码并向用户显示结果?

[英]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.

相关问题 Python:安全地呈现用户输入的 html 代码 - Python: Safely render user entered html code 如何使用Javascript或jQuery在div中呈现html代码 - How can I render html code in a div using Javascript or jQuery 如何在 HTML 页面中显示语法突出显示的 Python 代码? - How can I show syntax-highlighted Python code in a HTML-page? 如何从 php 代码中获取结果到 html 页面 - How can I take a result from a php code into html page 我如何在网站中像字符串一样显示html代码和javascript - How can i show html code and javascript like a string in website 如何在HTML页面中显示代码(特别是C ++)? - How can I show code (specifically C++) in an HTML page? 如何在HTML中正确显示此代码段? - How can I properly show this code snippet in HTML? 当我将 Python 代码保存到 html 时如何插入用户输入 - How to insert the user input for a Python code when I save it to html 如何在Python中使用“由HTML编写的” URL解析HTML代码? - How can I parse HTML code with “html written” URL in Python? 当我更改输入时,如何在 HTML 表单上自动显示 JavaScript function 的结果? - How can I automatically show the result of a JavaScript function on a HTML form, when I change the input?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM