【问题标题】:How to get a whole sqlite3 query onto a tkinter page如何在 tkinter 页面上获取整个 sqlite3 查询
【发布时间】:2019-04-22 09:48:00
【问题描述】:

我正在制作一个程序,您可以在其中搜索名称,然后会显示 sqlite3 数据库中的所有内容。

def search():
tk = Tk()
tk.geometry('500x500')
labe = Label(tk, text="Search all: fullname, major, gender, class one, class two, class three")
labe.pack()
ent = Entry(tk, bd=5)
ent.pack()
def dog():
    getted = ent.get()
    conn = sqlite3.connect('friend.db')
    if getted == "fullname":
        with conn:
            cursor = conn.cursor()
        cursor.execute('SELECT name1 FROM Photos')
        conn.commit()
        result = cursor.fetchall()
        for r in result:
            tkee = Tk()
            tkee.geometry('500x500')
            lab = Label(tkee, text=r)
            lab.pack()
            tkee.mainloop()

buty = Button(tk, text="Submit", command=dog)
buty.pack()

当我输入我想要所有全名时,程序运行良好,但幻灯片上只有一个名字。只有在我退出所有其他选项卡时才会显示其他名称。如果有人知道如何做到这一点,那将不胜感激。谢谢,贾马尔

【问题讨论】:

    标签: python tkinter sqlite


    【解决方案1】:

    正在发生的问题是您正在使用 for 循环。

    result = cursor.fetchall()
    for r in result:
            tkee = Tk()
            tkee.geometry('500x500')
            lab = Label(tkee, text=r)
            lab.pack()
            tkee.mainloop()
    

    如果你把它改成。

    result = cursor.fetchall()
    tkee = Tk()
    tkee.geometry('500x500')
    lab = Label(tkee, text=result)
    lab.pack()
    tkee.mainloop()
    

    然后就可以了

    【讨论】:

      猜你喜欢
      • 2011-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多