title: Python - close windows if exists in order in tkinter
body: <pre><code>    from tkinter import *
  
  class Main(Frame):
      def __init__(self, parent):
          Frame.__init__(self, parent)   
          self.parent = parent        
          self.initUI()
      def initUI(self):
          global canvas
          self.parent.title('Python')
          self.pack(fill = BOTH, expand = 1)
          canvas = Canvas(self)
          self.Label_My = Label(self, text = 'MyObject')
          self.Label_My.place(x = 0, y = 0)
  
          canvas.pack(fill = BOTH, expand = 1)
          canvas.update()
  class Main2(Frame):
      def __init__(self, parent):
          Frame.__init__(self, parent)   
          self.parent = parent        
          self.initUI()
      def initUI(self):
          global canvas
          self.parent.title('Python')
          self.pack(fill = BOTH, expand = 1)
          canvas = Canvas(self)
          self.Label_My = Label(self, text = 'MyObject2')
          self.Label_My.place(x = 0, y = 0)
  
      canvas.pack(fill = BOTH, expand = 1)
      canvas.update()
  
  root = Tk()
  ex = Main(root)
  root.geometry('700x500')
  
  root2 = Tk()
  ex2 = Main2(root2)
  root2.geometry('500x500')
  
  def d():
      if root2:
          root2.destroy()
      if root:
          root.destroy()
  </code></pre>
  
  <p>I created two tkinter window and I am going to close them if they exists, but it print the "root/root2" is not defined if I don't create them as windows.</p>
  
  <p>Also, I find that I have to close "root" first in order. 
  If I close "root2" first it prints "pythonw.exe has stopped working"</p>
  
  <p>My solution is to add "try-except-statement" before "if rootx", but I want a better solution.</p>