Python Tkinter 快速显示Table 中的数据

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

Python Tkinter 快速显示Table 中的数据

Author: Xiaohong
运行环境: OS: Win7 64位 专业版Pack1、Python: 3.7

功能: 把sqlite 3 DB 中 em_stock table 数据显示

缺点:以Label 方式显示数据,交互性差

main.py 脚本如下:

# em_stock 数据来源 见 Python Tkinter 练习1--抓取特定网页资料 中

from tkinter import *
# 导入访问Sqlite的模块
import sqlite3

def query_db():
    # 1 连接sqlite3 数据库
    database = sqlite3.connect("mrsoft.db")
    cursor = database.cursor()

    # 2 调用执行select语句查询数据
    sql = "select * from em_stock "
    cursor.execute(sql)

    #  3 通过游标的description属性获取列信息
    description = cursor.description

    #  4 使用fetchall获取游标中的所有结果集
    rows = cursor.fetchall()
    #  5 关闭游标
    cursor.close()
    #  6 关闭连接
    database.close()
    return description, rows

def main():
    description, rows = query_db()
    # 创建窗口
    win = Tk()
    win.title('数据查询')
    # 通过description获取列信息
    for i, col in enumerate(description):
        lb = Button(win, text=col[0], padx=15, pady=6)
        lb.grid(row=0, column=i

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值