Open In App
Related Articles

How to open a website in a Tkinter window?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In this article, we are going to see how we can open a website in the Tkinter window. We can open a website in Tkinter using webview. This library allows us to view the HTML content in its GUI window.  

Syntax to install Tkinter and webview using the below commands.

pip install tk
pip install pywebview

Method 1: Using  webview.create_window() and webview.start() function

In this method, we are use webview.create_window() and webview.start() function to open website in Tkinter. create_window() function is create window for website and start() function display this website on screen. Follow the below steps to open a website in Tkinter using this method.

  • Import Tkinter and webview libraries.
  • define an instance of Tkinter.
  • Set the size of your window.
  • Call webview.create_window() function.

Example:

Python3

# Import tkinter and webview libraries
from tkinter import *
import webview
  
# define an instance of tkinter
tk = Tk()
  
#  size of the window where we show our website
tk.geometry("800x450")
  
# Open website
webview.create_window('Geeks for Geeks', 'https://geeksforgeeks.org')
webview.start()

                    

Output:

Method 2: Using webbrowser.open() function

In this method. we use webbrowser.open() function. This function opens the requested page using the default browser. Follow the below steps to open a website in Tkinter using this method.

  • Import Tkinter and webview libraries.
  • define an instance of Tkinter.
  • Set the size of your window.
  • Call webbrowser.open() function.

Example:

Python3

# import required library
import webbrowser
from tkinter import *
  
# creating root
root = Tk()
  
# setting GUI title
root.title("WebBrowsers")
  
# setting GUI geometry
root.geometry("660x660")
  
# call webbrowser.open() function.
webbrowser.open("www.instagram.com")

                    

Output:



Last Updated : 28 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads