【发布时间】:2018-02-18 08:13:46
【问题描述】:
我希望 Python 在标签上显示来自 Access 的数据。我试图这样做,但它不起作用。没有错误,但标签显示pypyodbc.Cursor object at 0x05E02990。我该怎么办?谢谢
from tkinter import *
import pypyodbc
import ctypes
#Create connection
con = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:/Users/HP/Desktop/PITL;DBQ=C:/Users/HP/Desktop/PITL/PITL.mdb;')
cursor = con.cursor ()
form = Tk ()
form.title ("Main")
form.geometry ('400x400')
form2 = Tk ()
form2.title ("Main")
form2.geometry ('400x400')
form2.withdraw()
def Show():
cursor.execute ("SELECT Law_ID FROM Laws WHERE Fine=1")
a=cursor.execute
for a in cursor:
print ("Law ID where Fine is 1 is", a)
Label(form2, text=cursor).pack()
form.withdraw()
form2.deiconify()
Button(form, text = 'PUSH ME', command = Show).pack()
form.mainloop ()
con.commit ()
cursor.close ()
con.close ()
【问题讨论】:
-
将
print ("Law ID where Fine is 1 is", a)替换为print ("Law ID where Fine is 1 is", list(a))会发生什么? -
@Deadlock 它不会更改标签中的文本
标签: python sql ms-access select tkinter