Open In App

Python OpenCV – destroyWindow() Function

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.




# 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:

Article Tags :