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()