'Is there a way to import an excel file into the treeview widget without it overwriting other buttons that I have created in tkinter?

When I open the excel file that I'm trying to work with using the treeview tkinter widget the treeview overwrites everything else including my buttons in the frame. I've tried messing with my frames but haven't been able to find a fix.

Before:

enter image description here

After: enter image description here

Heres the code for my frames: and treeview widget:

    MainFrame=Frame(self.root, bd=5, width=1350, height=1350, bg="yellow", relief=RIDGE) MainFrame.grid()

    FrameMain=Frame(MainFrame, bd=5, width=1300, height=1300,padx=5,bg="light grey", relief=RIDGE)
    FrameMain.pack(side=RIGHT)

    Frame0=Frame(FrameMain, bd=2, width=1350, height=800,padx=5,bg="light grey", relief=RIDGE)
    Frame0.grid(row=0, column=0)
    Frame1=Frame(FrameMain, bd=2, width=1350, height=800,padx=5,bg="light grey", relief=RIDGE)
    Frame1.grid(row=1, column=0)
    Frame2=Frame(FrameMain, bd=2, width=1350, height=800,padx=5,bg="light grey", relief=RIDGE)
    Frame2.grid(row=2, column=0)

    self.tree=ttk.Treeview(Frame1)
    self.label=Label(Frame1, text=' ')
    self.label.pack(pady=55, padx= 175)'''

And code for one of my buttons:

      self.btnShowInventory= Button(Frame2, padx=18, pady=2, bd=2, fg="black", font= 
      ('arial', 9, 'bold'), width=14,bg="light grey", text="Open Inventory File", command= openFile).grid(row=0, column=1)

As well as the code I'm using to open the excel file:

       def openFile():
            filename = filedialog.askopenfilename(
                    title="Open a File", 
                    filetype=(("xlxs files", ".*xlsx"),("All Files", "*.*"))
            )
            if filename:
                    try:
                            filename = r"{}".format(filename)
                            df = pd.read_excel(filename)
                    except ValueError:
                            self.label.config(text="File could not be opened")
                      # Clear all the previous data in tree
            clear_treeview()

            # Add new data in Treeview widget
            self.tree["column"] = list(df.columns)
            self.tree["show"] = "headings"


            for col in self.tree["column"]:
                    self.tree.heading(col, text=col)

            df_rows = df.to_numpy().tolist()
            for row in df_rows:
                    self.tree.insert("", "end", values=row)

            self.tree.pack()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source