如何在画布上打印sqlite3查询结果作为矩阵?

时间:2018-06-07 20:00:18

标签: tcl tk

我想以矩阵的形式放置sqlite3查询的结果并将其打印在tk画布上。查询从数据库返回表的三列。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

为什么不使用tktable,而不是使用画布。绘制线条和格式化项目到列的所有工作都已完成。

#!/usr/bin/tclsh
# We need these otherwise it will not work
package require sqlite3
package require Tktable

# open database - in this case stockbox.db in the current directory
sqlite3 db stockbox.db

# Set up the titles
set models(0,0) "Model"
set models(0,1) "Width"
set models(0,2) "Length"

# Start with 1 for the title
set rows 1
set cols 3

# Perform query, extract result into models
db eval {SELECT model_id,width, length FROM tbl_model} {
    set models($rows,0) $model_id
    set models($rows,1) $width
    set models($rows,2) $length
    incr rows
}
db close

# Create the table
table .table -variable models -titlerows 1 -width $cols -height 10 -rows $rows -yscrollcommand ".ys set"
scrollbar .ys -command ".table yview"
pack .table .ys -side left -fill y
相关问题