首页 > 解决方案 > 以可读格式显示来自 psycopg2 的行

问题描述

我正在使用 python tkinter 从 postgres 获取一些记录并在布局上显示相同的记录,我用于使用列表框获取和列出的代码如下:

def get_search(id):
    conn = psycopg2.connect(dbname="postgres", user="postgres", password="passw0rd", host="localhost", port="5432")
    cur = conn.cursor()
    query = 'select * from table where id=%s;'
    cur.execute(query, (id,))
    row = cur.fetchall()
   listbox = Listbox(frame, width=20, height=1)
    listbox.grid(row=9, column=1)
    listbox.insert(END, row)
   listbox = Listbox(frame, width=20, height=10)
    listbox.grid(row=9, column=1)
    for x in row:
    listbox.insert(END, x)
    conn.commit()
    conn.close()

但是,显示的数据很简单,空格作为分隔符。在列表框中进一步添加或使用其他内容是否可行,以便每行的每一列单独显示在单独的框中,或者列值可以由不同的分隔符分隔。

标签: pythontkinterlistbox

解决方案


推荐阅读