“Tkinter Treeview” Ответ

Tkinter Treeview

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
Colorful Curlew

Python 3 Tkinter Treeview пример

# How to create a basic Treeview
tv = Treeview(self)  		# could also include columns with
tv['columns'] = 'Column2'	# Treeview(master, column=('yourcolumnname'))
tv.heading('#0', text='Heading1')  # '#0' standard name for the first column
tv.heading('Column2', text='I am the SECOND column')
parentrow = tv.insert('', 0, text="ParentRow", values=1)
tv.insert(parentrow, 1, text="Level2", values=2)  # subrow
tv.pack()

# if you put a tuple for values, then they will be iterated for each of your columns
# example in this Treeview tv:
tv['columns'] = ('C2', 'C3')
tv.insert('', 2, text='proove', values=('for', 'you'))

# sidenote: in the example I found they used 'end' as index for the subrow
EndOSos

Ответы похожие на “Tkinter Treeview”

Вопросы похожие на “Tkinter Treeview”

Смотреть популярные ответы по языку

Смотреть другие языки программирования