title: Tkinter remove stored file from memory
body: <pre><code>    from Tkinter import *
      import Tkinter as tk
      import ttk
      import tkFileDialog
      import numpy as np
      import matplotlib
      matplotlib.use("TkAgg")
      import matplotlib.pyplot as plt
      from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
      from matplotlib.figure import Figure
  
      class Look():
          def __init__(self, master):
              self.master = master
              self.master.title("Demo")
              self.master.configure(background = "grey91") #the color will be changed later
              self.master.minsize(500, 300) # width + height
              self.master.resizable(False, False)
  
              self.top_frame = ttk.Frame(self.master, padding = (10, 10))
              self.top_frame.pack()
  
              ttk.Button(self.top_frame, text = "Load file", command = self.load_file,
                 style = "TButton").pack()
  
              ttk.Button(self.top_frame, text = "Reset", command = self.clear_file,
                     style = "TButton").pack()
  
              ttk.Button(self.top_frame, text = "Plot", command = self.plot_file,
                                style = "TButton").pack()
  
              self.bottom_frame = ttk.Frame(self.master, padding = (10, 10))
              self.bottom_frame.pack()
  
              self.fig = plt.figure(figsize=(12, 5), dpi=100) ##create a figure; modify the size here
              self.fig.add_subplot()
  
              plt.title("blah")
  
              self.canvas = FigureCanvasTkAgg(self.fig, master = self.bottom_frame)
              self.canvas.show()
              self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
  
              self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.bottom_frame)
              self.toolbar.update()
              self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
  
          def load_file(self):
              self.file =  tkFileDialog.askopenfilename(defaultextension = ".txt", filetypes = [("Text Documents", "*.txt")])
  
          def clear_file(self):
              self.fig.clf()
              self.fig.add_subplot()
  
              plt.xticks()
              plt.yticks()
  
              self.canvas.draw()
  
  
          def plot_file(self):
              self.r, self.g = np.loadtxt(self.file).transpose()
              self.fig.clf()
              plt.plot(self.r, self.g)
              self.canvas.show()
  
  
      def main():
          root = Tk()
          GUI = Look(root)
          root.mainloop()
  
      if __name__ == "__main__": main()
  </code></pre>
  
  <p>The code above creates a program has three buttons. The Load file buttom loads a txt file, Reset button is supposed to clear the plot and delete the file just loaded into the memory. Plot button is to plot the figure onto canvas below.</p>
  
  <p>I have a question about how to write function associated with Reset function, i.e. clear_file function. Currently what it does is just clear the plot from canvas. But it seems the file that has been loaded to plot is stored in memory, since click again Plot, it will display the plot. My goal is to use Reset button to bring it to a fresh start--nothing stored in memory. I know loading a new file will overwrite the previous file. But when there are multiple buttons for loading different files, the situations could become complicated. Therefore I hope Reset can do the job.
  If you want to try this little program, you may create a simple txt with two column data to be loaded into the program.</p>
  
  <p>Thanks.</p>