Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display rendered html content in text widget of tkinter in python 3.4.x

I want to display my mails as it is in text widget of tkinter in python 3.4. It can be printed as HTML formatted way by using message.HTMLBody. How do I render it in my text widget and display the content

like image 887
Ashish Raj Avatar asked May 07 '16 03:05

Ashish Raj


2 Answers

I've managed to render simple html tags using tkhtml.

Install using pip3 install tkinterhtml, then, using the package example:

from tkinterhtml import HtmlFrame

frame = HtmlFrame(root, horizontal_scrollbar="auto")
 
frame.set_content("<html></html>")
 

If you want to directly render a webpage, you can do this to request and render it:

import urllib
frame.set_content(urllib.request.urlopen("https://duckduckgo.com").read().decode())

Hope it helps :)

like image 176
Lucas Azevedo Avatar answered Sep 26 '22 07:09

Lucas Azevedo


Short of anything past very basic HTML tkinter just wasn't built for this. There's tkhtml as one option, but anything past basic html you'll want to look elsewhere. Tk can do a lot of amazing things, but embedding webpages / content isn't really one of them.

If you just want the text / some basic images / formatting from your mail, then you can scrape the data and then render and format it through the standard tk widgets.

I don't really like recommending other packages / options as it tends to be highly opinionated, but check out PyQt. Specifically, the QtWebkit.

like image 45
Pythonista Avatar answered Sep 23 '22 07:09

Pythonista