title: Save the state of top level page in tkinter
body: <p>I tried to create a selection page on the top of my root page in my App using <code>tk.Toplevel()</code> function in tkinter. The new page has add button which create new option on the selection page. The simplified version of my code is demonstrated below:</p>
  
  <pre><code>import tkinter as tk
  
  
  class demo:
      lines = []
      def __init__(self, master):
          self.master = master
          self.add_button = tk.Button(self.master, text="+",
                                       command=self.add,
                                       width=3)
  
          self.add_button.pack()
          self.lines = []
  
  
      def add(self):
          line = []
          line.append(tk.Checkbutton(self.master, variable=tk.StringVar(value="0"))) # 5
          self.lines.append(line)
          self.show()
      def show(self):
          self.add_button.pack()
          for l in self.lines:
              l[0].pack()
  
  def new_window(master):        
      NewWindow = tk.Toplevel(master)
      demo(NewWindow)            
  
  
  root = tk.Tk()
  
  tk.Button(root, text="selection page",
                               command=lambda: new_window(root),
                               width=30).pack()
  
  root.mainloop()
  </code></pre>
  
  <p>What I want is that when I close the new page it maintains its state, i.e. when I create some checkboxs and fill some of them when I close the window it remains the same; but it starts over.</p>
  
  <p>How can I implement that?</p>