Python Forum
Hardest time getting DataFrame to populate Tree Widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hardest time getting DataFrame to populate Tree Widget
#1
I am very new to any GUI coding. I chose to work with Tkinter instead of PyQt. I have the basics down as far as the foundation of the GUI and have begun to make each separate frame. One of these frames will be for viewing generated invoices. The problem that I am encounter though is populating the data to the correct layout. I have data populated in the tree widget currently, but it is complete messed up. I have attached an image below. Here is the code I am currently working with. It's not a lot, I just can't figure out for the life of me what changes I need to make.

   

imp_df = pd.read_csv(r"V:\Invoices\Test Invoices.csv")

class ViewDataFrame(tk.Frame):


    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        tk_table = ttk.Treeview(self, columns=imp_df.columns.values)

        tk_table.heading('#0', text='Invoice Number')
        tk_table.heading('#1', text='Invoice Date')
        tk_table.heading('#2', text='Description')
        tk_table.heading('#3', text='Quantity')
        tk_table.heading('#4', text='Class')
        tk_table.heading('#5', text='Job')
        tk_table.heading('#6', text='Terms')
        tk_table.heading('#7', text='Items')
        tk_table.heading('#8', text='Amount')
        tk_table.heading('#9', text='PO Number')
        tk_table.heading('#10', text='Memo')
        tk_table.heading('#11', text='IsToEmail')

        def list_df():
            for each_rec in range(len(imp_df)):
                tk_table.insert("", tk.END, values=imp_df.loc[each_rec])
Reply
#2
(Oct-15-2018, 06:45 PM)WuchaDoin Wrote: imp_df.loc[each_rec]
Try printing that out inside your loop, so you can make sure it's actually what you expect it to be. It looks like the headers are being added to each row.
Reply
#3
(Oct-15-2018, 07:01 PM)nilamo Wrote:
(Oct-15-2018, 06:45 PM)WuchaDoin Wrote: imp_df.loc[each_rec]
Try printing that out inside your loop, so you can make sure it's actually what you expect it to be. It looks like the headers are being added to each row.

That is a stellar idea. It frustrates me that I overlooked that idea. I'll see what I get. Thank you very much.

You were right. It seems my headers are getting placed repeatedly. The data prints fine, but the headers are colliding with the data (I am assuming).

I removed the headers to see what it would do and sure enough, the headers don't affect the data. It seems the headers from the DataFrame are getting repeated as well as not falling in the right column. I just can't figure out what to add/edit.
Reply
#4
The tree widget is splitting the data by spaces. If I assign the description column only, then it clearly shows that it is separating the data based on spaces, not column values. I would post a screenshot, but it would be sensitive data.

Solved it! The argument "value" in Treeview.insert is expecting a list. After I changed my code to
tk_table.insert("", tk.END, values=list(imp_df.loc[each_rec]))
it worked perfectly!
Here is the link to the solution I found.
https://groups.google.com/forum/#!msg/co...xRSDrKOl4J
Reply
#5
Thanks for updating us!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] populate a QListWidget devilonline 1 1,574 Apr-10-2023, 02:52 AM
Last Post: deanhystad
  [PyQt] [Solved]Populate ComboBox with for loop? Extra 3 2,137 Jul-31-2022, 09:01 PM
Last Post: Extra
  Problems getting tk Combobox contents to populate properly dford 4 3,799 Jan-08-2022, 02:39 PM
Last Post: dford
  Auto populate dictionary with names/values of QT widgets cjh 1 2,935 Mar-23-2021, 02:56 PM
Last Post: deanhystad
  [PyQt] How to populate a treeview on a GUI with a dictionary mart79 1 8,238 Aug-05-2019, 01:30 PM
Last Post: Denni
  populate list with images and be able to select them ricardons 0 2,129 Jan-11-2019, 03:45 PM
Last Post: ricardons

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020