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 make python code faster 
Python :: plotly color specific color 
Python :: python tkinter entry widget 
Python :: python turn positive into negative 
Python :: download csv file from jupyter notebook 
Python :: for loop get rid of stop words python 
Python :: python switch statement 
Python :: python generate set of random numbers 
Python :: django start app 
Python :: Python code to find Area of Rectangle 
Python :: import fernet 
Python :: python gui 
Python :: python create file in current directory 
Python :: compare times python 
Python :: rolling window pandas 
Python :: python - find columns that are objects 
Python :: how to kill a script if error is hit python 
Python :: logging.basicConfig() 
Python :: python dict sortieren 
Python :: update xls file using python 
Python :: how to download from url in python 
Python :: how to remove some characters from a string in python 
Python :: Python message popup 
Python :: example of ternary operator in python 
Python :: python get numbers after decimal point 
Python :: installing required libraries in conda environment 
Python :: python import file from different directory 
Python :: open url from ipywidgets 
Python :: weighted average in python pandas 
Python :: tuple index in python 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =