TKINTER连接到MS Access数据库
我正在尝试使用TKINTER进行GUI选择MS Access数据库。我遇到了一个错误:“一般错误无法打开进程0xcb8螺纹0x39b8 dbc 0x1D234678“指向连接线的进程0xcb8 thread 0x39b8 dbc 0x39b8 dbc 0xcb8 thread 0xcb8 thread”的通用错误。为什么这不起作用。
import pandas as pd
import pyodbc
import numpy as np
from tkinter import *
from tkinter import ttk, filedialog
from tkinter.filedialog import askopenfile
import os
# Create an instance of tkinter frame
win = Tk()
# Set the geometry of tkinter frame
win.geometry("700x350")
def open_file():
file = filedialog.askopenfile(mode='r', filetypes=[('MS Access File', '*.accdb')])
if file:
filepath = os.path.abspath(file.name)
Label(win, text="The File is located at : " + str(filepath), font=('Aerial 11')).pack()
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ = ' + filepath)
qry=("select * from Table1")
dataf = pd.read_sql(qry, conn)
conn.close()
# Add a Label widget
label = Label(win, text="Browse for file", font=('Georgia 13'))
label.pack(pady=10)
# Create a Button
ttk.Button(win, text="Browse", command=open_file).pack(pady=20)
win.mainloop()
I'm trying to make a GUI using tkinter to select the MS Access Database. I get an error: "General error Unable to open registry key Temporary (volatile) Ace DSN for process 0xcb8 Thread 0x39b8 DBC 0x1d234678" pointing to the connection line. Why doesn't this work.
import pandas as pd
import pyodbc
import numpy as np
from tkinter import *
from tkinter import ttk, filedialog
from tkinter.filedialog import askopenfile
import os
# Create an instance of tkinter frame
win = Tk()
# Set the geometry of tkinter frame
win.geometry("700x350")
def open_file():
file = filedialog.askopenfile(mode='r', filetypes=[('MS Access File', '*.accdb')])
if file:
filepath = os.path.abspath(file.name)
Label(win, text="The File is located at : " + str(filepath), font=('Aerial 11')).pack()
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ = ' + filepath)
qry=("select * from Table1")
dataf = pd.read_sql(qry, conn)
conn.close()
# Add a Label widget
label = Label(win, text="Browse for file", font=('Georgia 13'))
label.pack(pady=10)
# Create a Button
ttk.Button(win, text="Browse", command=open_file).pack(pady=20)
win.mainloop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论