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

前端 未结 2 1536
名媛妹妹
名媛妹妹 2020-12-16 08:28

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

2条回答
  •  死守一世寂寞
    2020-12-16 08:46

    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("")
     
    

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

提交回复
热议问题