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
#8
Ref the above for the record I was using .csv files that were in the format.

"Car"
"Bus"
"Train"
"Boat"
"Motor cycle"


In the case of any entry with white space e.g "Motor cycle", this would appear in the combobox as {Motor cycle}

Having looked into this further and the .csv files I was using I can see that

a .csv file in the format ,Car,Bus,Train,Boat,Motor cycle the code below gives me what I was after.

In the case of the user selecting 'Car' as option 1 the callback loads the car options into combobox 2

,Ford,B M W,Seat,Honda,Volkswagen"

I believe that i am now providing .csv files in the correct way and using combobox and csv.reader in the correct way.


# METHOD #2
with open('Menus_Vend/MAIN.csv', newline='') as csvfile:
      spamreader = csv.reader(csvfile , delimiter=',')
      Tup1 = ()
      for Tup1 in spamreader:
       print(Tup1)
      csvfile.closed
ComboGrp1 = ttk.Combobox(frame_Grps, width=10)
ComboGrp1.place(x=40, y=10)
ComboGrp1['values']=(Tup1)
ComboGrp1.bind("<<ComboboxSelected>>", CBackComboGrp1)
def CBackComboGrp1(eventObject):

 with open('Menus_Vend/'+ (eventObject.widget.get()) +'.csv', newline='') as csvfile:
      spamreader = csv.reader(csvfile , delimiter=',')
      Tup2 = ()
      for Tup2 in spamreader:
        ComboGrp2['values'] = (Tup2)
        csvfile.closed
Reply


Messages In This Thread
RE: Reading data into a Combobox from a .CSV file - by KevinBrown - Apr-14-2019, 11:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Sad problems with reading csv file. MassiJames 3 657 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Reading a file name fron a folder on my desktop Fiona 4 931 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,118 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Reading a file JonWayn 3 1,112 Dec-30-2022, 10:18 AM
Last Post: ibreeden
  Reading Specific Rows In a CSV File finndude 3 1,003 Dec-13-2022, 03:19 PM
Last Post: finndude
  Excel file reading problem max70990 1 904 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  Reading All The RAW Data Inside a PDF NBAComputerMan 4 1,361 Nov-30-2022, 10:54 PM
Last Post: Larz60+
  Replace columns indexes reading a XSLX file Larry1888 2 997 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  Reading Data from JSON tpolim008 2 1,100 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Failing reading a file and cannot exit it... tester_V 8 1,838 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