Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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)

like image 219
dccsillag Avatar asked Feb 10 '23 07:02

dccsillag


2 Answers

I've managed to render simple html tags using tkhtml

just 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 :)

like image 179
Lucas Azevedo Avatar answered Feb 12 '23 22:02

Lucas Azevedo


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.

like image 23
Dan Field Avatar answered Feb 12 '23 21:02

Dan Field