TKINTER连接到MS Access数据库

发布于 2025-01-28 12:11:01 字数 1134 浏览 2 评论 0原文

我正在尝试使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文