The Wayback Machine - https://web.archive.org/web/20230315005648/https://www.geeksforgeeks.org/python-opencv-destroywindow-function/
Skip to content
Related Articles
Open in App
Not now

Related Articles

Python OpenCV – destroyWindow() Function

Improve Article
Save Article
  • Last Updated : 03 Jan, 2023
Improve Article
Save Article

Python Opencv destroyWindow() function is used to close particular windows. This function takes one parameter that is window name which you want to close or destroy and it doesn’t return anything.

Syntax: cv2.destroyWindow(window_name)

Parameter:

  • window_name: name of the window which you want to destroy

Return: This function doesn’t return anything

destroyWindow() Function – Examples

In this example, we will read one image and create multiple windows of it. Then we will destroy any particular window by using the destroyWindow() function.

Python3




# import cv2 library
import cv2
  
# Read an image
img = cv2.imread("Documents/Image3.jpg",
                 cv2.IMREAD_COLOR)
  
# create two windows of images and 
# give different window name to each
cv2.imshow("I1", img)
cv2.imshow("I2", img)
  
# we will wait for user to press any key
cv2.waitKey(0)
  
# after user pressed any key only 'I2' named
# window will be closed and another image
# remains as it is.
cv2.destroyWindow("I2")

Output:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!