为什么此功能仅打印表的第一行?
import PySimpleGUI as sg
import sqlite3
con = sqlite3.connect("BakeryDatabase.db")
cur = con.cursor()
dic={}
cur.execute('SELECT * FROM Customer_Info')
dic['Customer_Info']=cur.fetchall()
def customerinfo():
for row in range(len(dic['Customer_Info'])):
print(dic['Customer_Info'][row])
sg.theme('LightYellow')
event, values = sg.Window('Customers Information', [[sg.Text('Please select option.')],
[sg.Button('Add'),
sg.Button('Delete'),
sg.Button('Modify'),
sg.Cancel()]]).read(close=True)
当称为此功能时,仅打印表的第一行。我希望它打印出整个表格,以便用户可以决定要更改的内容。同样,当我单击任何按钮时,输出将打印出下一行,直到显示整个表为止。
import PySimpleGUI as sg
import sqlite3
con = sqlite3.connect("BakeryDatabase.db")
cur = con.cursor()
dic={}
cur.execute('SELECT * FROM Customer_Info')
dic['Customer_Info']=cur.fetchall()
def customerinfo():
for row in range(len(dic['Customer_Info'])):
print(dic['Customer_Info'][row])
sg.theme('LightYellow')
event, values = sg.Window('Customers Information', [[sg.Text('Please select option.')],
[sg.Button('Add'),
sg.Button('Delete'),
sg.Button('Modify'),
sg.Cancel()]]).read(close=True)
When called this function only prints first row of the table. I would like it to print out entire table so the user can then decide what they want to change. Also when I click any of the buttons the output prints out next row until the entire table is shown.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先 - 正如其中一条评论所指出的那样,您对词典的迭代似乎很奇怪。
第二:
为什么您将所有行都拿到字典中,然后在上面迭代?您可以直接迭代光标:
First - your iteration over a dictionary seems odd, as pointed out in one of the comments.
Second:
Why do you fetch all rows to a dictionary and then iterate over it? you can directly iterate over a cursor: