I am trying to create a GUI using tkinter and I know how to connect to MS access but how do I connect to it using tkinter with a file open button. If anyone could point me in the right direction.
I’m new to tkinter myself, so I’ve yet to create a working app that uses file access, but I’ve started to gather some info and put this together as tester; I hope you find it of use.
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog as fd
from tkinter.messagebox import showinfo
root = tk.Tk()
root.title('Tkinter Open File Dialog')
root.resizable(False, False)
root.geometry('300x150')
def select_file():
filetypes = (
('Text files','*.txt'),
('All files', '*.*')
)
filename = fd.askopenfilename(
title='Open a file',
initialdir='/home/',
filetypes=filetypes)
showinfo(
title='Selected File',
message=filename
)
# open button
open_button = ttk.Button(
root,
text='Open a File',
command=select_file
)
open_button.pack(expand=True)
# run the application
root.mainloop()
1 Like