How do I open a website in a Tkinter window?

Tkinter offers many built-in functions and methods to help construct user-friendly applications. To open a webpage in a Tkinter window, you can use the pywebview library, which allows users to view HTML content in a native GUI window.

Installing pywebview

First, install the pywebview library using pip ?

pip install pywebview

Basic Implementation

To create a window that displays web content, use the create_window() method to specify the window title and URL, then call webview.start() to launch the window ?

import tkinter as tk
import webview

# Create an instance of tkinter frame
win = tk.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()

Alternative Approach: Embedding with tkinter.html

You can also embed web content directly in a Tkinter frame using the tkinter.html module (requires additional setup) ?

import tkinter as tk
from tkinter import ttk
import webbrowser

def open_website():
    webbrowser.open("https://www.tutorialspoint.com")

root = tk.Tk()
root.title("Website Opener")
root.geometry("400x200")

button = ttk.Button(root, text="Open TutorialsPoint", command=open_website)
button.pack(pady=50)

root.mainloop()

Key Features

Method Pros Cons
pywebview Embedded browser, full web functionality External dependency
webbrowser module Built-in Python, simple Opens in system browser

Output

Running the pywebview code will display the requested URL content in a dedicated window that integrates with your Tkinter application.

TutorialsPoint - pywebview TutorialsPoint Learn technologies online with tutorials Website content displayed here... Navigation, links, and interactive elements work as expected in the embedded browser.

Conclusion

Use pywebview for embedding full web functionality in your Tkinter application. For simple webpage opening, the built-in webbrowser module provides a lightweight alternative that opens URLs in the system browser.

Updated on: 2026-03-26T18:48:16+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements