After a bit more searching a head scratching, I've tidied up METHOD #2 in the main adding the csvfile.closed line. This now just uses a tuple to load in the data from the .csv file into the combobox.
I have laid this out here such that it may be of some use to other newbies who may ask the same questions as me.
I now have 3 combo boxes and a hierarchical process, ComboGrp2 data is dependant on the selection made in ComboGrp1 and ComboGrp3 dependant on ComboGrp2.
Consider MAIN.csv as the seed file at the top of the hierarchy.
e.g loading .csv files for Vehicles > Cars > Fords as the user makes selections.
The callbacks for loading the appropriate .csv into the comboboxes are shown below.
The selections are saved in SQLite by .get and retrieved with .set statements.
In order to allow no selection each of the .csv files has a blank entry " " on row one.
# METHOD #2
with open('Menus_Vend/MAIN.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile , delimiter=',')
Tup1 = ()
for row in spamreader:
Tup1 = [tuple(row)for row in spamreader]
csvfile.closed
frame_Grps = Frame(window, relief = 'sunken', bd= 2, width = 180, height = 90 )
frame_Grps.place (x = 700, y = 200)
ComboGrp1 = ttk.Combobox(frame_Grps, width = 10)
ComboGrp1.place(x = 10 ,y =10)
# Hard code the values for initial tests
#ComboGrp1['values']=('Test1','Test2','Test3')
ComboGrp1['values']=(Tup1) #Data from the .csv file and tuple above METHOD #2
ComboGrp2 = ttk.Combobox(frame_Grps, width = 10)
ComboGrp2.place(x = 10 ,y =30)
#ComboGrp2['values']=(Tup2) # Assigned only after Grp1 Callback
ComboGrp3 = ttk.Combobox(frame_Grps, width = 10)
ComboGrp3.place(x = 10 ,y =50)
#ComboGrp3['values']=(Tup3) # Assigned only after Grp2 Callback
ComboGrp1.bind("<<ComboboxSelected>>", CBackComboGrp1)
ComboGrp2.bind("<<ComboboxSelected>>", CBackComboGrp2)
def CBackComboGrp1(eventObject):
with open('Menus_Vend/'+ (eventObject.widget.get()) +'.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile , delimiter=',')
Tup2 = ()
for row in spamreader:
Tup2 = [tuple(row)for row in spamreader]
ComboGrp2['values']=(Tup2)
csvfile.closed
def CBackComboGrp2(eventObject):
with open('Menus_Vend/'+ (eventObject.widget.get()) +'.csv', newline='') as csvfile:
spamreader = csv.reader(csvfile , delimiter=',')
Tup3 = ()
for row in spamreader:
Tup3 = [tuple(row)for row in spamreader]
ComboGrp3['values']=(Tup3)
csvfile.closed
# FileSave
Grp1 = ComboGrp1.get() # new Grp1
Grp2 = ComboGrp2.get() #
GRp3 = ComboGrp3.get() #
# File Open
ComboGrp1.set(id_exists[14])
ComboGrp2.set(id_exists[15])
ComboGrp3.set(id_exists[47]) # New Grp 3