我有一个看不清楚的问题,我在这里请求帮助。我不知道为什么当我运行代码时,行打印两次而不是一次。我的数据库中有 5 行,当我执行代码时,它返回 10 行,前 5 行,然后重复 5 行。
from tkinter import *
from tkinter import ttk
from PIL import ImageTk, Image
import sqlite3
class fed:
db_name = 'database.db'
def __init__(self, window):
self.wind = window
self.wind.title('ligth')
self.wind.iconbitmap('doggy.ico')
self.wind.geometry("500x200")
self.get_name()
def run_query(self, query, parameters = ()):
with sqlite3.connect(self.db_name) as conn:
cursor = conn.cursor()
result = cursor.execute(query, parameters)
conn.commit()
return result
def get_name(self):
query = 'SELECT * FROM name'
db_rows = self.run_query(query)
for row in db_rows:
print(row)
if __name__ == '__main__':
window = Tk()
fed(window)
application = fed(window)
window.mainloop()
浮云间
相关分类