【问题标题】:Why is only half of my tuple being read when I am trying to input it into a treeview为什么当我尝试将元组输入到树视图时只有一半被读取
【发布时间】:2019-10-17 18:21:49
【问题描述】:

tkinter treeview

my tuple list

基于我的图像“我的元组列表”和图像“Tkinter 树视图”,由于某种原因,它不会在一列中显示公司名称,在第二列中显示值。我无法弄清楚错误。任何帮助表示赞赏

import Tkinter as tk
import ttk
from function4 import *

root = tk.Tk()

treeView = ttk.Treeview(root)
# set up the columns and headings
# In reality "Member ID" would be exported from the database
treeView["columns"] = ["CompanyName", "AwardedAmount"]
treeView["show"] = "headings"
treeView.heading("CompanyName", text="Company Name")
treeView.heading("AwardedAmount", text="Awarded Amount")
treeView.grid(columnspan=2)


# Add content using (where index is the position/row of the treeview)
# iid is the item index (used to access a specific element in the treeview)
# you can set iid to be equal to the index
tuples = reg_company_award(supplierNameList, companyNameList, awardList)


index = iid = 0
for values in tuples:
    print values
    treeView.insert("", 'end', values=values)
    index = iid = index + 1

root.mainloop()

基于图像“我的元组列表”,树视图上的预期输出应在一列上显示公司名称,在另一列上显示值。但是当前的树视图如图“tkinter treeview”所示

【问题讨论】:

  • Edit 你的问题并显示 ONE print values 的输出。拜托,没有图像!

标签: python tkinter treeview


【解决方案1】:

您的 reg_company_award(supplierNameList, companyNameList, awardList) 似乎只返回一个字符串列表或元组。

当您的 tuples 变量包含值时确实是元组...

tuples = (('388 PTE LTD.', 0.0), ('3M TECHNOLOGIES PTE LTD.', 3245234.2))

您期望的结果会出现在窗口中。

当tuples 只是一个列表/元组时......

tuples = ('388 PTE LTD.', '3M TECHNOLOGIES PTE LTD.')

您在屏幕截图中附加的图案将出现。

您应该修复 reg_company_award 函数/方法的返回值。

(下次也请提供一些数据而不是图片)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-03
    • 2020-05-05
    • 1970-01-01
    • 2011-02-09
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多