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)
我有以下用于 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)