thank you in advance. I am very new to Tkinter, hope you understand. My question is, now I'm developing a software, a certain page of this software is to upload a csv file, and load the first 10 records of it. What I'm thinking is to use Tkinter Treeview to display them. However, I'm now having issue of displaying it. This is my function of uploading the file and display it.
`
def UploadAction(contentFrame, s_homeMainFrame, topFrame):
filename = filedialog.askopenfilename(title="Select file", filetypes=(("CSV Files", "*.csv"),))
#=== if user didnt choose a file after dialog appears =====
if filename == "":
print("")
else:
for widget in topFrame.winfo_children():
widget.destroy()
lbl_title = Label(topFrame, text="Upload Data", font=('arial', 20))
lbl_title.pack(fill=X)
for widget in contentFrame.winfo_children():
widget.destroy()
lbl_preview_data = Label(contentFrame, text="Preview Data:", font=('times new roman', 20))
lbl_preview_data.pack(side='top')
df = pd.read_csv(filename)
print(df)
resultTree = ttk.Treeview(contentFrame)
df_col = df.columns.values
resultTree['columns'] = (df_col)
counter = len(df)
for x in range(len(df_col)):
resultTree.column(x, width=100)
resultTree.heading(x, text=df_col[x])
for i in range(counter):
rowLabels = df.index.tolist()
resultTree.insert('', 0, values=(df[df_col[x]][i]))
resultTree.pack(side=TOP)
btn_clean_data = Button(contentFrame, text="Clean Data", width=20, command="")
btn_clean_data.pack(side='top', pady=30)
Click_Save = partial(Save_Data, contentFrame, s_homeMainFrame, topFrame, filename)
btn_save_data = Button(contentFrame, text="Save Data", width=20, command=Click_Save)
btn_save_data.pack(side='top', pady=40)`
I do not have any error on this, however, the display field is displaying everything in reverse order except the header, and everyting is displayed in the first column.
As in something like this:
userid | email | username | password | role | status
Available
Available
Supermarket Staff
aaa
admin
aaa
admin_1
aaa@gmail.com
admin@gmail.com
2
1
But this is certainly not what I expect. What I expect is to display top 10 records nicely. As in something like this:
userid | email | username | password | role | status
1 | admin@gmail.com | admin_1 | admin | Admin | Available
2 | aaa@gmail.com | aaa | aaa | Supermarket Staff | Available
which is exactly the same as how the records are displayed in the csv file. I would like to know what is the problem here. Many Thanks!