【问题标题】:Python: How Can I Render HTML Code And Show The Result To The User?Python:如何渲染 HTML 代码并向用户显示结果?
【发布时间】:2015-07-06 15:35:42
【问题描述】:

我正在构建一个 python 应用程序,它应该获取特定的 HTML 代码,呈现它并在 tkinter gui 中向用户显示结果。我怎样才能做到这一点?我更喜欢有一些内置模块,或者一些我可以使用 easy_install 来获取的模块。感谢您的任何提前。

(我将 OSX Yosemite 与 python 2.7 一起使用)

【问题讨论】:

    标签: html python-2.7 osx-yosemite


    【解决方案1】:

    将您的 HTML 保存到文件位置,并使用 webbrowser 模块的 open() 函数显示它;有关文档,请参阅 https://docs.python.org/2/library/webbrowser.html

    【讨论】:

    • 我的真正意思是在 html 窗口中渲染 html。
    【解决方案2】:

    我已经设法使用 tkhtml 呈现简单的 html 标签

    只需pip3 install tkinterhtml

    并且,来自包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())
    

    希望对你有帮助:)

    【讨论】:

    • 这里的根是什么?
    • @SamZiggler root = tk.Tk() 你的 tk 根。
    • 不错。我从那里尝试过,但没有渲染 CSS 的东西
    • @SamZiggler 你是对的,它不能处理 CSS。我也遇到了这个问题,然后选择使用技术上是 python 的烧瓶应用程序。
    猜你喜欢
    • 2016-12-16
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多