Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

python 3 tkinter treeview example

# 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
Comment

PREVIOUS NEXT
Code Example
Python :: how to drop duplicate columns in pandas that dont have the same name? 
Python :: python use variable name as variable 
Python :: python for loop index 
Python :: python staticmethod property 
Python :: print without newline 
Python :: request download file 
Python :: how to kill somene 
Python :: can serializer returns an object in django 
Python :: python list contains 
Python :: math module in python 
Python :: copy dataframe columns names 
Python :: python __lt__ 
Python :: python sort an array 
Python :: how to write a dataframe to s3 object in python 
Python :: Local to ISO 8601: 
Python :: Multidimensional Java Array 
Python :: python is not clickable at point (434, 682). Other element would receive the click: 
Python :: wap in python to check a number is odd or even 
Python :: text classification 
Python :: list vs tuple python 
Python :: request session python 
Python :: split the column value and take first value in pandas 
Python :: python get text of QLineEdit 
Python :: python os.path.join 
Python :: isupper() in python 
Python :: how to give float till 5 decimal places 
Python :: Find the length of a nested list in python 
Python :: find index of element in array python 
Python :: black code formatter 
Python :: a list of keys and a list of values to a dictionary python 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =