import PySimpleGUI as sg
import pymysql
#打开数据库 主机地址 端口号 用户名 密码 数据库名
db=pymysql.Connect(host='localhost',port=3306,user='root',passwd='password',db='barcode32',charset='utf8')
#创建游标
cursor=db.cursor()
sql='select * from run32code'
cursor.execute(sql)
data=cursor.fetchall()
print(data)
headings = ['President', 'Date of Birth']
data = [
['Ronald Reagan', 'February 6'],
['Abraham Lincoln', 'February 12'],
['George Washington', 'February 22'],
['Andrew Jackson', 'March 15'],
['Thomas Jefferson', 'April 13'],
['Harry Truman', 'May 8'],
['John F. Kennedy', 'May 29'],
['George H. W. Bush', 'June 12'],
['George W. Bush', 'July 6'],
['John Quincy Adams', 'July 11'],
['Garrett Walker', 'July 18'],
['Bill Clinton', 'August 19'],
['Jimmy Carter', 'October 1'],
['John Adams', 'October 30'],
['Theodore Roosevelt', 'October 27'],
['Frank Underwood', 'November 5'],
['Woodrow Wilson', 'December 28'],
]
layout = [[sg.Table(data, headings=headings, justification='left', key='-TABLE-')],]
window = sg.Window("Title", layout, finalize=True)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
print(event, values)
window.close()