I want to use a combox widget to display a list of vehicles which are populated by querying an access DB. Heres relevant code
from O365 import *
import tkinter as tk
from tkinter import ttk
from tkcalendar import *
import pyodbc
root = tk.Tk()
root.title('Loan Car Manager')
root.geometry('800x1200')
style = ttk.Style(root)
load_loan_vehicle_list_button = tk.Button(root, command = get_active_loan_cars, text = "Load / Refresh")
load_loan_vehicle_list_button.place(x=50 , y=50)
conn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;{FIL=MS Access};DriverId=25;DefaultDir=C:\Users\James\Documents;DBQ=C:\Users\James\Documents\Database1.accdb;')
cursor = conn.cursor()
def get_active_loan_cars():
global loan_list
cursor.execute("SELECT Loan_make , Loan_model , Loan_rego FROM Loan_vehicle_data WHERE is_active = True")
for row in cursor.fetchall():
loan_list = []
loan_list.append(row)
loan_car_drop_down = ttk.Combobox(root)
loan_car_drop_down.place(x=50 , y=70)
loan_car_drop_down['values'] = loan_list
print(loan_list)
root.mainloop()
When I run this, it queries the DB as expected and returns the vehicles into a list loan_list
.. When I insert the list into to combobox
using loan_car_drop_down['values'] = loan_list
it displays the list but the records are displayed on 1 line.. Eg:
When I print(loan_list)
it returns:
[('Hyundai', 'Elantra', 'TEST123')] [('Hyundai', 'I30', 'ABC123')]
My question is how can I get these records to display on seperate lines of the combobox
widget.
Heres a picture referancing my goal.. Ignoring the months displayed in this example I would like to replace those with :
Hyundai', 'Elantra', 'TEST123' 'Hyundai', 'I30', 'ABC123'