How do I open a website in a Tkinter window?


Tkinter offers many built-in functions and methods that contain several utility functions to help us construct a user-friendly application. In tkinter, if you want to open a webpage, you can use the built-in Python library, webview, which allows the users to view the HTML content in its own native GUI window. You can install the webview library by using the following command −

pip install pywebview

To create a window that will open the requested HTML content, you have to first create a window container by using the create_window(win_title, 'URL') method and specify the URL in the method. This will create a new window that will open the requested URL and display the content

Example

The following example demonstrates how you can open a webpage in a Tkinter GUI window.

# Import the required libraries
from tkinter import *
import webview

# Create an instance of tkinter frame or window
win = Tk()

# Set the size of the window
win.geometry("700x350")

# Create a GUI window to view the HTML content
webview.create_window('tutorialspoint', 'https://www.tutorialspoint.com')
webview.start()

Output

Running the above code will display the request URL web content in the tkinter window.

Updated on: 16-Dec-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements