User choosing data file

I have some code where the user is meant to choose a file and from that, plot a graph from the datafile in the next frame. After the file is chosen, a dataframe is created from the .csv file and then on the next frame, a plot can be seen of the first and second column.

I see that the problems occur due to variables being defined before the file is called in, however I am unsure how to mitigate the problem. The two frames need to stay separate if possible as this is technically only a subsection of the code.

Any help would be greatly appreciated.

import csv
import pandas as pd
import tkinter as tk
from tkinter import filedialog
from tkinter import ttk
from tkinter import messagebox
import matplotlib

matplotlib.use("TkAgg")

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg

from matplotlib.figure import Figure


fig = Figure(figsize=(5,4), dpi=100)
ax= fig.add_subplot(111)

LARGE_FONT= ("Verdana", 12)

class GUI(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)
        tk.Tk.wm_title(self, "GUI")

        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand = True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (Home, Graph):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(Home)




    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()


class Home(tk.Frame):

    def __init__(self, parent, controller):
        self.controller = controller
        tk.Frame.__init__(self,parent)
        label = tk.Label(self, text="Start Page", font=LARGE_FONT)
        label.pack(pady=10, padx=10)



        ftypes = [
                ('CSV files','*.csv')
        ]

        def browsefunc2():
            filename = tk.filedialog.askopenfilename(filetypes=ftypes)
            pathlabel2.config(text=filename)

        df = pd.read_csv(filename, encoding='latin-1')

        browsebutton = tk.Button(self, borderwidth=0, text="Browse", command=browsefunc2, height=1, width=10)
        browsebutton.pack()

        pathlabel2 = tk.Label(self, borderwidth=0)
        pathlabel2.pack()



        button2 = ttk.Button(self, text="Graph",
                             command=lambda: controller.show_frame(Graph))
        button2.pack()

class Graph(tk.Frame):

    def __init__(self, parent, controller):
        self.controller = controller
        tk.Frame.__init__(self,parent)
        label = tk.Label(self, text="Graph", font=LARGE_FONT)
        label.pack(pady=10,padx=10)
        canvas = FigureCanvasTkAgg(fig, self)


        df.plot.scatter('column 1', 'column 2', ax=ax)

        canvas.draw()
        canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)



        button3 = ttk.Button(self, text="Back",
                            command=lambda: controller.show_frame(Home))
        button3.pack()

app = GUI()
app.mainloop()