title: Python Tkinter file dialog
body: <p>I am writing a small python program with tkinter as the gui to select excel files and open them, I got to the point where I can select the file and open them. My problem is when the user dont't select a file and click cancel It produces and error.  How to continue code if the user does not select a file in tkinter file dialog?</p>
  
  <pre><code>import pandas as pd
  import tkinter as tk
  from tkinter import filedialog
  import openpyxl
  from openpyxl import load_workbook
  import os
  import sys
  import numpy as np
  
  
  root = tk.Tk()
  
  canvas1 = tk.Canvas(root, width=300, height=300, bg='lightsteelblue')
  canvas1.pack()
  
  
  def getExcel():
      global df
  
      import_file_path = filedialog.askopenfilename()
      df = pd.read_excel(import_file_path)
      book = load_workbook(import_file_path)
      writer = pd.ExcelWriter(import_file_path, engine='openpyxl')
      writer.book = book
      x3 = (df.loc[(df['Var Cost'] &lt; -500) | (df['Var Cost'] &gt; 500)])
      df3 = pd.DataFrame(x3)
      df3.to_excel(writer, sheet_name='VarianceSorted')
      writer.save()
      writer.close()
      command = import_file_path
      os.system(command)
  
  
  def end():
      sys.exit()
  
  
  browseButton_Excel = tk.Button(text='Import Excel File', command=getExcel, bg='green', fg='white', font=('helvetica', 12, 'bold'))
  canvas1.create_window(150, 150, window=browseButton_Excel)
  
  quitbutton = tk.Button(text='Quit', command=end, bg='green', fg='white', font=('helvetica', 12, 'bold'))
  canvas1.create_window(200, 200, window=quitbutton)
  
  root.mainloop()
  </code></pre>