Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Open CV
  • scikit-image
  • pycairo
  • Pyglet
  • Python
  • Numpy
  • Pandas
  • Python Database
  • Data Analysis
  • ML Math
  • Machine Learning
  • NLP
  • Deep Learning
  • Deep Learning Interview Questions
  • ML Projects
  • ML Interview Questions
  • 100 Days of Machine Learning
Open In App
Next Article:
Python OpenCV - destroyWindow() Function
Next article icon

Python OpenCV - destroyAllWindows() Function

Last Updated : 03 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Python Opencv destroyAllWindows() function allows users to destroy or close all windows at any time after exiting the script. If you have multiple windows open at the same time and you want to close then you would use this function. It doesn't take any parameters and doesn't return anything. It is similar to destroyWindow() function but this function only destroys a specific window unlike destroyAllWindows().

Example 1: Closing window using  destroyWindow() function

In the Python script given below, we have created two windows named 'P' and 'Q' respectively that displayed an image of "gfg_logo.png" using the cv2.imshow() function that is supposed to display window 'P' first on the screen but before calling the waitKey() function to delay the closing of windows, we will destroy only the window named 'P' with destroyWindow('P') function by passing the window name 'P' as its argument. We will see that the window 'Q' is only displayed on the screen which will close only when the user closes it.

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 key is pressed cv2.waitKey(0) 

Output:

Example 2:  Closing window using destroyAllWindows() function

In this case, instead of calling destroyWindow() to delete or close a particular window, we will use destroyAllWindows() to destroy all windows on the screen here we have called this function before waitKey(0), so the images will not at all displayed on the screen. DestroyAllWindows() is just a good coding practice. 

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 key is pressed cv2.waitKey(0) 

Output:


Next Article
Python OpenCV - destroyWindow() Function

Y

yashgupta0524
Improve
Article Tags :
  • Python
  • OpenCV
  • Python-OpenCV
Practice Tags :
  • python

Similar Reads

  • 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 des
    1 min read
  • Python OpenCV - waitKey() Function
    waitkey() function of Python OpenCV allows users to display a window for given milliseconds or until any key is pressed. It takes time in milliseconds as a parameter and waits for the given time to destroy the window, if 0 is passed in the argument it waits till any key is pressed.  Examples 1: Disp
    1 min read
  • Python OpenCV - namedWindow() Function
    Python OpenCV namedWindow() method is used to create a window with a suitable name and size to display images and videos on the screen. The image by default is displayed in its original size, so we may need to resize the image for it to fit our screen. Created windows are referred by their names and
    3 min read
  • Python OpenCV - waitKeyEx() Function
    Python OpenCv waitKeyEx() method is similar to waitKey() method but it also returns the full key code. The key code which is returned is implementation-specific and depends on the used backend: QT/GTK/Win32/etc. Syntax: cv2.waitKey(delay) Parameters: delay: The time in milliseconds after which windo
    2 min read
  • Python OpenCV - selectroi() Function
    In this article, we are going to see an interesting application of the OpenCV library, which is selectROI(). With this method, we can select a range of interest in an image manually by selecting the area on the image. Syntax:  cv2.selectROI(Window_name, source image) Parameter: window_name:  name of
    3 min read
  • Python OpenCV - moveWindow() Function
    When we show the image using the imshow() function output window will open at the center or default position of a computer screen. Even if there are multiple image windows all windows will be displayed at the same position and we have to move windows manually. If we want to show image windows at a s
    2 min read
  • How to Install OpenCV Python Headless?
    OpenCV (Open Source Computer Vision Library) is a powerful open-source computer vision and machine learning software library. It enables developers to access a wide range of algorithms for various computer vision tasks. In this article, we will see how to install OpenCV Python Headless. What is Open
    2 min read
  • Python OpenCV - resizeWindow() Function
    resizeWindow() method in Python OpenCV is used to resize window displaying images/videos to a specific size. The specified window size is for images excluding toolbars. This only works for created windows having flags other than CV_WINDOW_AUTOSIZE. Syntax: cv2.resizeWindow(window_name, width, height
    1 min read
  • Python OpenCV - getWindowImageRect() Function
    Python OpenCV getWindowImageRect() Function returns the client screen coordinates, along with the width and height of the window containing the picture. Syntax of cv2.getWindowImageRect() Syntax: cv2.getWindowImageRect(window_name) Parameter:  window_name - Name of the window displaying image/video
    3 min read
  • wxPython - Detach() function in wx.MenuBar
    In this article we are going to learn about Detach() function associated with wx.MenuBar class of wxPython. Detach() function simply detaches the menubar associated/attached with the frame. Detach() function takes no arguments. Syntax: wx.MenuBar.Detach(self) Parameters: Detach() function takes no a
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences