Python Forum
Insert csv data rows into a tree widget
Thread Rating:
  • 3 Vote(s) - 2.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert csv data rows into a tree widget
#1


I'm a beginner so dont beat me up too much :) .I have a program where a user enters a product number into a field and clicks a search button, the program then opens a csv file (see below), looks for that product number and should then only display (by inserting that data into a treeview) the data relevant, stopping once blank rows occur - this indicates the end of the part information and the start next part.

Example of the csv is below (excuse the use of the error box)
Error:
Product PartDesc Drawings Issues Documents 1-1841111-2 bad feeling Dwg1 Iss A c:\company\docs\tfpp\widget1.xls Dwg2 Iss B c:\company\docs\tfpp\bob.pdf Dwg25 Iss Z c:\company\docs\tfpp\itsatrap.pdf 1-1841111-4 tribble Dwg3 Iss C c:\company\docs\tfpp\wibble.xls 1-1841111-5 nothing Dwg4 Iss D c:\company\docs\tfpp\rocket.pdf Dwg5 Iss E c:\company\docs\tfpp\dwg1.doc
Unfortunately when I run the code I can only get a single csv row to display and have not been able to work out how get subsequent rows, stopping at a blank row. I am however, not convinced that the below code although its displays a single line as expected is operating correctly.

def search(self):
        if self.SOentry.get() != "":
            x = self.dwgtree.get_children()
            for item in x:
                self.dwgtree.delete(item)
            self.partdesc.delete(0,'end')
                
            with open("c:\python\projects\somedwgs.csv") as csvfile:
                    reader = csv.DictReader(csvfile)
                    for row in reader:
                        result=(row['Product'])
                        if self.SOentry.get() == result:
                                descr=(row['PartDesc'])
                                descDwg=(row['Drawings'])
                                descIss=(row['Issues'])
                                descDscr=(row['Documents'])
                                self.partdesc.insert(0,descr)
                                while True:
                                    #if row['PartDesc'] != "":
                                    if descDwg != "":
                                        self.dwgtree.insert("",'end',values=(descDwg,descIss,descDscr))
                                        next(reader)
                                        break
Reply


Messages In This Thread
Insert csv data rows into a tree widget - by LMP2016 - Nov-09-2017, 08:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to insert Dashed Lines in between Rows of a tabulate output Mudassir1987 0 592 Sep-27-2023, 10:09 AM
Last Post: Mudassir1987
  how do you style data frame that has empty rows. gsaray101 0 579 Sep-08-2023, 05:20 PM
Last Post: gsaray101
  Plot a pandas data fram via pyqtgraph with an modul import and qt designer widget Nietzsche 0 930 May-29-2023, 02:42 PM
Last Post: Nietzsche
  (Python) Pulling data from UA Google Analytics with more than 100k rows into csv. Stockers 0 1,335 Dec-19-2022, 11:11 PM
Last Post: Stockers
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 2,098 Dec-12-2022, 08:22 PM
Last Post: jh67
  How to insert different types of data into a function DrData82 0 1,284 Feb-10-2022, 10:41 PM
Last Post: DrData82
  How to read rainfall time series and insert missing data points MadsM 4 2,323 Jan-06-2022, 10:39 AM
Last Post: amdi40
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,684 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Iterating Through Data Frame Rows JoeDainton123 2 3,021 Aug-09-2021, 07:01 AM
Last Post: Pedroski55
Lightbulb [Solved] df.loc: write data in certain rows ju21878436312 1 1,765 Jun-28-2021, 06:49 AM
Last Post: ju21878436312

Forum Jump:

User Panel Messages

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