【问题标题】:sql output in treeview columns using tkinter module in python使用python中的tkinter模块在treeview列中输出sql
【发布时间】:2015-08-28 10:21:35
【问题描述】:

我正在尝试使用 python 3.4 中的 tkinter 模块将 sql 查询的 2 个不同返回输出到树视图小部件中的相应列当我运行定义在第一列下方的命令时,会正确打印所有条目,但名称列会打印名称所有行中的第一个结果,而不是每行的名称。关于我做错了什么有什么想法吗?

    def refreshtrade():

        for i in treeview.get_children():
            treeview.delete(i)


            #order number
        refreshtradein = conn.cursor()                
        refreshtradein.execute("SELECT increment_id FROM mg_ikantam_buyback_order")

            #first name
        names =conn.cursor()
        names.execute("SELECT customer_firstname FROM mg_ikantam_buyback_order")# WHERE increment_id = 'buyback-%s'" %(tradeinentryfield.get() ))

        for n in names:
            for r in refreshtradein:
                     treeview.insert('',0,r,text = r, values=(n,'Mercedes', 'Purchased', '8-34-15'))



        refreshtradein.close()
        conn.close()

【问题讨论】:

    标签: python mysql python-3.x tkinter treeview


    【解决方案1】:

    为什么要使用两个不同的游标,并因此使用两个嵌套的 for 循环?您知道如何评估嵌套的 for 循环吗?

    querycursor = conn.cursor()
    querycursor.execute(SELECT increment_id, customer_firstname FROM mg_ikantam_buyback_order)
    
    for row in querycursor:
        print(row[0])
        print(row[1])
    

    哦,关于你的 where 子句。永远不要做这样的参数替换。安全隐患很大

    here如何正确操作

    【讨论】:

    • 感谢您的反馈,我不知道,所以感谢您的洞察力。我会试着理解你的反应,因为我对编码很陌生,而且对我来说还不直观,但我会用我的结果来回应。再次感谢
    • 当我尝试你的建议时,我得到一个 AttributeError: 'tuple' object has no attribute 'increment_id' 错误
    • 谢谢伙计,我显然对此还是很陌生,感谢您的帮助。这使它完全输出了我需要的东西。我尝试了非安全风险 sql 查询利用,但是当我输入逗号时出现语法错误:/
    猜你喜欢
    • 2015-04-25
    • 2019-02-07
    • 2016-01-22
    • 1970-01-01
    • 2018-09-24
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-01
    相关资源
    最近更新 更多