Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python OpenCV – destroyAllWindows() Function

  • Last Updated : 17 Oct, 2021

Python Opencv destroyAllWindow() function allows users to destroy all windows at any time. It doesn’t take any parameters and doesn’t return anything. It is similar to destroyWIndow(). destroyWindow() only destroys a specific window but in the case of destroyAllWindow() it destroys all windows.

Example 1: Using destroyWindow()

We make two windows of names ‘P’ and ‘Q’ having an image of gfg logo and then before calling the waitKey() function to delay the closing of windows, we will destroy only the window named ‘P’ with destroyWindow(). We will see that the window ‘Q’ is delayed to be closed.

Python




# importing cv2 module
import cv2
  
# read the image
img = cv2.imread("gfg_logo.png")
  
# showing the images
cv2.imshow('P', img)
cv2.imshow('Q', img)
  
# Destroying the window named P before
# calling the waitKey() function
cv2.destroyWindow('P')
  
# using the wait key function to delay the
# closing of windows till any ke is pressed
cv2.waitKey(0)

Output:

Example 2: Using destroyAllWindow()

In this case, instead of calling destroyWindow() to delete a particular window, we will use destroyAllWindow() to destroy all windows. So here window name ‘Q’ will not be visible.

Python




# importing cv2 module
import cv2
  
# read the image
img = cv2.imread("gfg_logo.png")
  
# showing the images
cv2.imshow('P', img)
cv2.imshow('Q', img)
  
# Destroying All the windows
cv2.destroyAllWindows()
  
# using the wait key function to delay
# the closing of windows till any ke is pressed
cv2.waitKey(0)

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!