Python Forum
Reading data into a Combobox from a .CSV file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading data into a Combobox from a .CSV file
#5
Thank you Larx60+ for relocating this where I should have put it.


I have delved into this further to see if I can get a solution..


Method 2: Prints out the first item from the .csv file and does not print any more lines.
The tuple misses the first line from the .csv file but gets picks up all the rest of the items.


Method 1: Using a tuple and a list to allow me to append each row to the list before converting back to a tuple.
Not very subtle but it works for the meantime.

I can't believe that there is not a better solution but my inexperience can't take me beyond this at the moment.


Another point that I note and need to understand is this: If I have any white space between words in the .csv for example "DADMIN Database Admin" when this is loaded into the combobox we get {DADMIN Database Admin} as the combobox selection. If we have other elements in the .csv such as "PIPING" or "ELEC" these appear as normal selections without the curly brackets, another riddle to solve.

I haven't thought to check on syntax within the brackets following the OPEN statement for example newline = '' etc.


# METHOD 1  use LIST and TUPLE TO obtain data from .csv file
with open('MAIN.csv', newline='') as csvfile:
      spamreader = csv.reader(csvfile , delimiter='"') 
      Tup1 = ()
      Lst1 = ()
      for row in spamreader:
       print(','.join(row))
       Lst1 = list(Tup1)
       Lst1.append(row)
       Tup1 = tuple(Lst1)


# METHOD #2       
# with open('MAIN.csv', newline='') as csvfile:
#      spamreader = csv.reader(csvfile , delimiter=',')
#      Tup1 = ()
#      for row in spamreader:
#       print(','.join(row))
#       Tup1 = [tuple(row)for row in spamreader]

      

ComboGrp1 = ttk.Combobox(window, width = 30, height = 20)
ComboGrp1.place(x = 500 , y = 110)
# Hard code the values
#ComboGrp1['values']=('Test1','Test2','Test3')
ComboGrp1['values']=(Tup1)

ComboGrp2 = ttk.Combobox(window, width = 10, height = 20)
ComboGrp2.place(x = 500 , y = 130)
I'd appreciate if anyone can shed light on these two questions.
Reply


Messages In This Thread
RE: Reading data into a Combobox from a .CSV file - by KevinBrown - Apr-01-2019, 05:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Sad problems with reading csv file. MassiJames 3 709 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Reading a file name fron a folder on my desktop Fiona 4 985 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,154 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Reading a file JonWayn 3 1,134 Dec-30-2022, 10:18 AM
Last Post: ibreeden
  Reading Specific Rows In a CSV File finndude 3 1,022 Dec-13-2022, 03:19 PM
Last Post: finndude
  Excel file reading problem max70990 1 918 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  Reading All The RAW Data Inside a PDF NBAComputerMan 4 1,416 Nov-30-2022, 10:54 PM
Last Post: Larz60+
  Replace columns indexes reading a XSLX file Larry1888 2 1,015 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  Reading Data from JSON tpolim008 2 1,137 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Failing reading a file and cannot exit it... tester_V 8 1,865 Aug-19-2022, 10:27 PM
Last Post: tester_V

Forum Jump:

User Panel Messages

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