# Tkinter to open Access database and load tables into combo box

**URL:** <https://discuss.python.org/t/tkinter-to-open-access-database-and-load-tables-into-combo-box/16181>\
**Category:** Python Help\
**Created:** [June 1, 2022, 7:58pm UTC](https://discuss.python.org/t/tkinter-to-open-access-database-and-load-tables-into-combo-box/16181 "2022-06-01T19:58:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![giszzmo](https://avatars.discourse-cdn.com/v4/letter/g/e36b37/32.png) [@giszzmo](https://discuss.python.org/u/giszzmo)\
**Post date:** [June 1, 2022, 7:58pm UTC](https://discuss.python.org/t/tkinter-to-open-access-database-and-load-tables-into-combo-box/16181/1 "2022-06-01T19:58:22Z")

</div>

I am creating a tkinter GUI where I need to open an Access database and create a list of available tables in a combo box so that I can choose which table I want and it can be stored into a variable and then used in the query. I can’t get the combo box to show. If anyone can point me in the right direction.

from tkinter import \*  
from tkinter import ttk, filedialog  
from tkinter.filedialog import askopenfile  
import os  
import pathlib  
from tkinter.messagebox import showinfo

win = Tk()

# Set the geometry of tkinter frame

win.title(‘D016 Database’)  
win.geometry(“1000x800”)

def open\_file():  
file = filedialog.askopenfile(mode=‘r’, filetypes=[(‘MS Access File’, ‘\*.accdb’)])  
global dataf

if file:  
filepath = os.path.abspath(file.name)  
Label(win, text="The File is located at : " + str(filepath), font=(‘Aerial 8’)).pack()  
conn = pyodbc.connect(r’Driver={Microsoft Access Driver (\*.mdb, \*.accdb)};‘r’DBQ=’+filepath+‘;’)

```
  #Get tables
  cursor = conn.cursor()
  for row in cursor.tables():
     table_combo['values'] = row.table_name
  
  #Create combobox
  my_combo = ttk.combobox(win, values=table_combo)
  my_combo(row=1, column=1, padx=10, pady=20)
  my_combo.current(0)
  my_combo.set(selected_table)

  qry=("select * from selected_table")
  dataf = pd.read_sql(qry, conn)
  conn.close()

```

#Access database Label widget  
label = Label(win, text=“Click the Button to browse the Files”, font=(‘Georgia 13’))  
label.pack(pady=10)

#Access database table  
label = Label(win, text=“Choose a table”, font=(‘Georgia 13’))  
label.pack(pady=30)

# Create a Browse Button

ttk.Button(win, text=“Browse”, command=open\_file).pack(pady=20)

win.mainloop()

---

<div class="post-metadata">

**Author:** ![rob42](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/rob42/32/8218_2.png) [@rob42](https://discuss.python.org/u/rob42)\
**Post date:** [June 1, 2022, 8:03pm UTC](https://discuss.python.org/t/tkinter-to-open-access-database-and-load-tables-into-combo-box/16181/2 "2022-06-01T20:03:37Z")

</div>

In the same way as you’ve used a the `.pack()` geometry manager for your other widgets, you need to do the same thing with your combo box.
