title: Python Tkinter access variable inside function for use outside of function
body: <p>I'm building a gui to get an excel file and calendar input from a user. I want to use the file path and calendar date outside the functions in which they are called. How might I accomplish this? I tried using global variables inside these functions but to no avail.</p>
  
  <pre><code>import tkinter as tk
  from tkinter import *, filedialog
  from tkcalendar import Calendar, DateEntry
  import pandas as pd
  from datetime import datetime
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.common.by import By
  
  root = Tk()
  
  def browse():
      root.filename = filedialog.askopenfile(initialdir="/downloads", title="Select a file",
                                             filetypes=((".xlsx files", "*.xlsx"), ("all files", "*.*")))
  
  def date_picker():
      top = tk.Toplevel(root)
      cal = Calendar(top, font="Arial 14", selectmode='day', locale='en_US', disabledforeground='red',
                     cursor="hand1", date_pattern='MM/dd/yyyy')
      cal.pack(fill="both", expand=True)
  
      def quit():
          top.destroy()
  
      tk.Button(top, text="ok", command=quit).pack()
  
  def exit():
  root.destroy()
  
  okButton = Button(root, text="OK", command=exit)
  stuLabel = Label(root, text="Date")
  calLabel = Label(root, text="Date to Start Summing")
  calButton = Button(root, text="Date", command=date_picker)
  fileButton = Button(root, text="File", command=browse)
  fileLabel = Label(root, text="Select a File")
  exitButton = Button(root, text="Exit")
  stuLabel.grid(row=0, column=0)
  calLabel.grid(row=1, column=0)
  fileLabel.grid(row=2, column=0)
  calButton.grid(row=1, column=1)
  fileButton.grid(row=2, column=1)
  okButton.grid(row=3, column=0)
  exitButton.grid(row=3, column=1)
  
  root.mainloop()
  
  browser = webdriver.Chrome()
  browser.get('a website')
  type(browser)
  
  delay = 20
  
  df = pd.read_excel(filename, Sheet_name=0, header=None) # Here I want to access the chosen file
  
  sum_start = browser.find_element_by_name('date') 
      sum_start.click()
      # clear date
      sum_start.clear()
      sum_start.send_keys(str(date) + Keys.ENTER) # Here I want to access the date selected by the user
  </code></pre>