How do I open a website in a Tkinter window?

I am trying to build a simple web browser with Tkinter. I would like to know how I can open a website in Tkinter/Python.


Solution 1:

You cannot easily do what you want. Tkinter has no way to render html. You would have to parse the HTML and CSS and Javascript yourself, and translate the information for display on a canvas or text widget.

If all you want to handle is paragraphs, bold, italic, and headings, it might not be too hard. To render most real-world html with css and javascript would likely take you thousands of hours of work to get right.

At one point there was an effort to create a tkinter html widget, but that project hasn't seen any significant activity in years (http://tkhtml.tcl.tk/), and as far as I know was never integrated with Tkinter. It showed a lot of promise, but it also showed that rendering HTML is a very, very difficult task.

Solution 2:

First, you can parse the HTML content with HTMLParser. Secondly (and this is a very in-depth process) you can display the data; as it's being parsed, in a canvas containing a bitmap, while detecting user input. That said, Bryan is correct.

Solution 3:

one way

import tkinter
import tkinter as tk
root = tk.Tk()
frame = tkinterweb.HtmlFrame(root)
frame.load_website('https://pokemondb.net/')    
frame.pack(fill="both", expand=True)
root.mainloop()