Python"非空格式字符串传递给对象.__格式__"将字符串插入tkinter文本小部件时

时间:2014-08-28 13:14:37

标签: python tkinter

我从数据库中获取一些数据,当我尝试将查询结果打印到tkinter Text Widget时,它显示错误:

    statTextField.insert(INSERT,("{0:28}{1:40}{2:20}{3:20}\n".format(row[0],row[1],row[2],row[3])))
TypeError: non-empty format string passed to object.__format__

查询的某些结果是正常数字,但是有空记录,它们是实际字符串“无”。当我只打印带有 jquartz_fired_triggers 表中的统计数据的记录时,没有问题。打印“空”记录时出现错误

jquartz_cron_triggers                         |                      |      
jquartz_fired_triggers  0.50000000000000000000|0.00000000000000000000|0.50000000000000000000
jquartz_job_details                           |                      |

以下是负责在tkinter Text小部件中打印所有内容的代码:

z3.execute("""SELECT relname,
                                case
                                  when (n_tup_ins + n_tup_upd + n_tup_del) > 0 then
                                    cast(n_tup_ins AS numeric) / (n_tup_ins + n_tup_upd + n_tup_del)
                                  else
                                    null
                                end AS ins_pct,
                                case
                                  when (n_tup_ins + n_tup_upd + n_tup_del) > 0 then
                                    cast(n_tup_upd AS numeric) / (n_tup_ins + n_tup_upd + n_tup_del)
                                  else
                                    null
                                end AS upd_pct,
                                case
                                  when (n_tup_ins + n_tup_upd + n_tup_del) > 0 then
                                    cast(n_tup_del AS numeric) / (n_tup_ins + n_tup_upd + n_tup_del)
                                  else
                                    null
                                end AS del_pct
                                FROM pg_stat_user_tables
                                ORDER BY relname;""")
    if(bool(z3.rowcount) == True):
        statTextField.insert(INSERT, "\n\n\nSTATYSTYKI INS/UPD/DEL\nRELNAME                                |   INSERTED |  UPDATED | DELETED\n")
        for row in z3.fetchall():
                statTextField.insert(INSERT,("{0:28}{1:40}{2:20}{3:20}\n".format(row[0],row[1],row[2],row[3]))) # <-------- Problem is here

代码应该能够打印数字数据和空记录。你知道怎么做吗?

P.S。我发现有类似问题的问题,但没有找到有关如何修复我的代码的有用信息

0 个答案:

没有答案