请问这个Python的代码错在了哪,为何连接了MySQL之后不能把数据显示在窗口上的文本框中? 10
import tkinter as tk
DBHOST='localhost'
DBUSER='root'#数据库用户名
DBPASS='1355'#数据库密码
DBNAME='dbtest1'#数据库的表名
def sure():
b=entry_usr_bno.get()
database7(b)
t=tk.Tk()
t.title("查询图书")
t.geometry("300x200")
tk.Label(t,text='图书编号: ').place(x=50,y=60)
var_usr_bno=tk.StringVar()
entry_usr_bno = tk.Entry(t,textvariable=var_usr_bno)
entry_usr_bno.place(x=120, y=60)
b=tk.Button(t,text='确定',command=sure).place(x=140,y=150)
def database7(b):
db=pymysql.connect(DBHOST,DBUSER,DBPASS,DBNAME)
cur=db.cursor()
sql=cur.execute('SELECT * FROM Student WHERE ID=%s',b)
db.commit()
if sql==0:
print(".... ")
else:
results=cur.fetchall()
for row in results:
id=row[0]
c=row[1]
break
val=str(c)
window=tk.Tk()
window.title('图书馆管理系统')
window.geometry('300x200')
var1=tk.StringVar()
l=tk.Label(window,bg='yellow',width=10,textvariable=var1)
l.pack()
var1.set(val) 展开
import pymysql
import tkinter as tk
DBHOST = 'localhost'
DBUSER = 'root'#数据库用户名
DBPASS = '123456'#数据库密码
DBNAME = 'test'#数据库的表名
window = tk.Tk()
window.title('图书馆管理系统')
window.geometry('300x200')
var1 = tk.StringVar()
l = tk.Label(window,bg='yellow',width=10,textvariable=var1)
l.pack()
def sure():
db = pymysql.connect(DBHOST, DBUSER, DBPASS, DBNAME)
cur = db.cursor()
cur.execute('SELECT * FROM user WHERE ID=1')
db.commit()
results = cur.fetchall()
for row in results:
print(row)
var1.set(row)
tk.Button(window, text='确定', command=sure).pack()
window.mainloop()