Python 使用pandas在tkinter中的treeview上更改/编辑excel中的信息?

Python 使用pandas在tkinter中的treeview上更改/编辑excel中的信息?,python,excel,pandas,tkinter,treeview,Python,Excel,Pandas,Tkinter,Treeview,我想知道如何从excel文件中编辑某些单元格,这些excel文件可以在pandas/treeview的tkinter中查看。到目前为止,我已经看到了excel,我现在正试图找到一种方法来编辑这个表格中的任何特定单元格。有什么建议,可以阅读的网站,或者我可以看的例子吗 def TreeviewTest(): global frame1 global file_frame global button1 global button

我想知道如何从excel文件中编辑某些单元格,这些excel文件可以在pandas/treeview的tkinter中查看。到目前为止,我已经看到了excel,我现在正试图找到一种方法来编辑这个表格中的任何特定单元格。有什么建议,可以阅读的网站,或者我可以看的例子吗

    def TreeviewTest():
        global frame1
        global file_frame
        global button1
        global button2
        global label_file
        global tv1
        # Frame for TreeView
        frame1 = tk.LabelFrame(ReturnWin, text="Excel Data")
        frame1.place(height=400, width=1000)

        # Frame for open file dialog
        file_frame = tk.LabelFrame(ReturnWin, text="Open File")
        file_frame.place(height=100, width=400, rely=0.65, relx=0)

        # Buttons
        button1 = tk.Button(file_frame, text="Browse A File", command=lambda: File_dialog())
        button1.place(rely=0.65, relx=0.50)

        button2 = tk.Button(file_frame, text="Load File", command=lambda: Load_excel_data())
        button2.place(rely=0.65, relx=0.30)

        # The file/file path text
        label_file = ttk.Label(file_frame, text="No File Selected")
        label_file.place(rely=0, relx=0)

        ## Treeview Widget
        tv1 = ttk.Treeview(frame1)
        tv1.place(relheight=1, relwidth=1)  # set the height and width of the widget to 100% of its container (frame1).

        treescrolly = tk.Scrollbar(frame1, orient="vertical",
                           command=tv1.yview)  # command means update the yaxis view of the widget
        treescrollx = tk.Scrollbar(frame1, orient="horizontal",
                           command=tv1.xview)  # command means update the xaxis view of the widget
        tv1.configure(xscrollcommand=treescrollx.set,
              yscrollcommand=treescrolly.set)  # assign the scrollbars to the Treeview Widget
        treescrollx.pack(side="bottom", fill="x")  # make the scrollbar fill the x axis of the Treeview widget
        treescrolly.pack(side="right", fill="y")  # make the scrollbar fill the y axis of the Treeview widget

    def File_dialog():
        """This Function will open the file explorer and assign the chosen file path to label_file"""
        filename = filedialog.askopenfilename(initialdir="/",
                                      title="Select A File",
                                      filetype=(("xlsx files", "*.xlsx"),("All Files", "*.*")))
        label_file["text"] = filename
        return None

    def Load_excel_data():
        """If the file selected is valid this will load the file into the Treeview"""
        file_path = label_file["text"]
        #df = df.fillna("")
        #pandas.DataFrame.fillna()
        try:
            excel_filename = r"{}".format(file_path)
            if excel_filename[-4:] == ".csv":
                df = pd.read_csv(excel_filename)
            else:
                #df = df.fillna("")
                df = pd.read_excel(excel_filename)



        except ValueError:
            tk.messagebox.showerror("Information", "The file you have chosen is invalid")
            return None
        except FileNotFoundError:
            tk.messagebox.showerror("Information", f"No such file as {file_path}")
            return None

        clear_data()
        tv1["column"] = list(df.columns)
        tv1["show"] = "headings"
        for column in tv1["columns"]:
            tv1.heading(column, text=column) # let the column heading = column name

        df_rows = df.to_numpy().tolist() # turns the dataframe into a list of lists
        for row in df_rows:
            tv1.insert("", "end", values=row) # inserts each list into the treeview.
          
        return None

    def clear_data():
        tv1.delete(*tv1.get_children())
        return None