📜  tkinter 树视图 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:23.350000             🧑  作者: Mango

代码示例2
def view_dfs(df1):
    df1 = df1.replace(np.nan, '', regex=True)
    table = tk.Tk()
    table.geometry("1220x500")
    table.pack_propagate(False)
    table.resizable(0, 0)

    frame = tk.LabelFrame(table, text="Report")
    frame.place(height=485, width=1200)

    # Treeview Widget
    tv1 = ttk.Treeview(frame, style="mystyle.Treeview")
    tv1.place(relheight=1, relwidth=1)

    treescrolly = ttk.Scrollbar(frame, orient="vertical", command=tv1.yview)
    treescrollx = ttk.Scrollbar(frame, orient="horizontal", command=tv1.xview)
    tv1.configure(xscrollcommand=treescrollx.set, yscrollcommand=treescrolly.set)
    treescrollx.pack(side="bottom", fill="x")
    treescrolly.pack(side="right", fill="y")
    
    def Load_excel_df1():
        tv1.delete(*tv1.get_children())
        tv1["column"] = list(df1.columns)
        tv1["show"] = "headings"
        for column in tv1["columns"]:
            tv1.column(column, width = 100) 
            tv1.heading(column, text=column)

        df_rows = df1.to_numpy().tolist()
        for row in df_rows:
            tv1.insert("", "end", values=row)
        return

    def exit_window():
        table.destroy()
        return

    Load_excel_df1()
    table.mainloop()
    return