繁体   English   中英

Python tkinter Treeview 列比指定的多

[英]Python tkinter Treeview more columns than specified

我有以下 ttk Treeview 代码:

listbox = ttk.Treeview(
    tab_player,
    columns=('Player', 'Rating', 'Price'),
    selectmode="extended",
)

listbox.heading('#0', text='Player', anchor=tk.CENTER)
listbox.heading('#1', text='Rating', anchor=tk.CENTER)
listbox.heading('#2', text='Price', anchor=tk.CENTER)
listbox.column('#0', stretch=tk.YES, minwidth=50, width=80)
listbox.column('#1', stretch=tk.YES, minwidth=50, width=20)
listbox.column('#2', stretch=tk.YES, minwidth=50, width=30)

listbox.grid(row=5, column=5, rowspan=7, sticky=W)

我的插入功能如下:

def insertitem():
        GUI.listbox.insert('', 'end', values = (GUI.listbox_content.get(), 
                                                GUI.listboxr_content.get(), 
                                                GUI.listbox_content_price.get()))

当我启动我的应用程序时,我有一个额外的列,插入的数据不是我想要的(数据在错误的列中)。

在此处输入图片说明

这是为什么?

"#0"始终指的是树列,而不是数据列。 因此,请改用"#1", "#2", "#3"并设置show="headings"来隐藏树列

listbox = ttk.Treeview(
    tab_player,
    columns=('Player', 'Rating', 'Price'),
    selectmode="extended",
    show="headings"  # hide the tree column
)

listbox.heading('#1', text='Player', anchor=tk.CENTER)
listbox.heading('#2', text='Rating', anchor=tk.CENTER)
listbox.heading('#3', text='Price', anchor=tk.CENTER)

listbox.column('#1', stretch=tk.YES, minwidth=50, width=80)
listbox.column('#2', stretch=tk.YES, minwidth=50, width=60)
listbox.column('#3', stretch=tk.YES, minwidth=50, width=60)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM