python - 以可读格式显示来自 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()
但是,显示的数据很简单,空格作为分隔符。在列表框中进一步添加或使用其他内容是否可行,以便每行的每一列单独显示在单独的框中,或者列值可以由不同的分隔符分隔。
解决方案
推荐阅读
- reactjs - 无法获取提交函数的输入值
- python - 如何使用 mechanize.Browser 填写表格?
- python - 使用随机生成的列索引和另一个张量更新张量
- c# - Blazor Radzen Grid 不显示任何数据
- macos - 无法使用 fileURL 在快捷方式中加载图像文件
- c++ - 向量内存布局的向量
- javascript - 如何在桌面和移动设备上显示数字输入的箭头?
- excel - 如何在 Excel VBA 中调用 dgemm?
- amazon-web-services - Google Tag Manager 不适用于 AWS S3 托管网站
- javascript - indexOf() 跳过了重复的元素 javascript