How to open a website in a Tkinter window?
Last Updated :
28 Feb, 2022
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
from tkinter import *
import webview
tk = Tk()
tk.geometry( "800x450" )
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 webbrowser
from tkinter import *
root = Tk()
root.title( "WebBrowsers" )
root.geometry( "660x660" )
webbrowser. open ( "www.instagram.com" )
|
Output:
Please Login to comment...