【问题标题】:How to iterate MySQL fetchall() results into tinter listbox and center results如何将 MySQL fetchall() 结果迭代到 tinter 列表框并居中结果
【发布时间】:2017-10-31 05:45:45
【问题描述】:

只是为了解释这里发生了什么:我有一个搜索功能,它使用用户输入 [givenLocation] 运行 MySQL 查询。它应该将查询的内容转储到列表框[self.lookuplist]。我的问题是,即使我正在使用 fetchall() 函数,它也只会转储第一个结果。我是一名自学成才的 Python 开发人员,但我无法从其他来源找到任何相关信息。这是我的代码:

def searchL_button(self):

    i = 0

    givenLocation = self.top3.searchEntry1.get()
    searchLookup = ("SELECT Status, Serial, Product_Code, Location FROM Registers WHERE Location = %s")
    cursor9.execute(searchLookup, [givenLocation])
    locRes = cursor9.fetchall() [i]

    for i in locRes:
        self.lookupList.insert(END, locRes)

【问题讨论】:

    标签: python mysql loops tkinter listbox


    【解决方案1】:

    您将变量 locRes 设置为仅包含查询的第一个结果。将最后几行更改为以下内容

    locRes = cursor9.fetchall()
    
    for curRes in locRes:
        self.lookupList.insert(END, curRes)
    

    【讨论】:

    • 感谢您的帮助!
    猜你喜欢
    • 2021-12-16
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多