Open In App

How to open a website in a Tkinter window?

Last Updated : 28 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
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:



Previous Article
Next Article

Similar Reads

Open a new Window with a button in Python-Tkinter
Python provides a variety of GUI (Graphic User Interface) such as PyQt, Tkinter, Kivy and soon. Among them, tkinter is the most commonly used GUI module in Python since it is simple and easy to learn and implement as well. The word Tkinter comes from the tk interface. The tkinter module is available in Python standard library.Note: For more informa
3 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
How to open External Programs using Tkinter?
Prerequisite: Tkinter, os Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications. In this article, w
2 min read
Transparent window in Tkinter
Prerequisite: Python GUI – tkinter Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. To create a transparent window, we will use the attributes() method. Syntax: root.attribut
1 min read
Python Tkinter - Frameless window
Prerequisite: Python GUI – tkinter Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. To create a Frameless window, we will use the overrideredirect() method. Syntax: root.over
1 min read
Dynamically Resize Buttons When Resizing a Window using Tkinter
Prerequisite: Python GUI – tkinter Button size is static, which means the size of a button cannot be changed once it is defined by the user. The problem here is while resizing the window size, it can affect the button size problem. So the solution here is, make a dynamic button, which means the button size will change as per window size. Let's unde
2 min read
How to Set a Tkinter Window With a Constant Size?
Prerequisite: Python GUI – tkinterminsizemaxsize The task here is to produce a Tkinter window with a constant size. A window with a constant size cannot be resized as per users' convenience, it holds its dimensions rigidly. A normal window on the other hand can be resized. Approach Import moduleDeclare Tkinter objectCreate a fixed sized window usin
2 min read
How to Create Full Screen Window in Tkinter?
Prerequisite: Tkinter There are two ways to create a full screen window in tkinter using standard python library for creating GUI applications. Method 1: Using attributes() function Syntax: window_name.attributes('-fullscreen',True) We will set the parameter '-fullscreen' of attributes() to True for setting size of our window to fullscreen and to F
3 min read
How to close a window in Tkinter?
Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using tkinter is an easy task.
1 min read
How to Close a Tkinter Window With a Button?
Prerequisites: Tkinter Python's Tkinter module offers the Button function to create a button in a Tkinter Window to execute any task once the button is clicked. The task can be assigned in the command parameter of Button() function. Given below are various methods by which this can be achieved. Method 1: Using destroy() Non-Class method Approach: I
3 min read
three90RightbarBannerImg