_tkinter.TclError: Invalid column index g

最近在学Python3的tkinter模块使用tkinter的Treeview做表格展示信息,出现如下错误_tkinter.TclError: Invalid column index g

观察代码后发现是在columnheading中加了两列,并没有在定义的时候添加,导致报错,加上之后代码正常运行

下面附上完整代码,列表展示并带有滚动条

from tkinter import *
from tkinter.ttk import Treeview
from tkinter.ttk import Scrollbar

# 顶层窗口
top = Tk()  # 创建顶层窗口
top.title("工具")
top.geometry('650x405')  # 290 160为窗口大小,+10 +10 定义窗口弹出时的默认展示位置
# 创建一个表格
table = Treeview(top, show='headings', column=('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'), height=16)
# 创建滚动条
vbar = Scrollbar(top, orient="vertical", command=table.yview)
# 定义树形结构与滚动条
table.configure(yscroll=vbar.set)
table.grid(row=2, columnspan=7)
vbar.grid(row=2, column=7, sticky='NS')  # N/S/E/W,分别代表上对齐/下对齐/左对齐/右对齐
table.column('a', width=60, anchor="center")
table.column('b', width=60, anchor="center")
table.column('c', width=60, anchor="center")
table.column('d', width=60, anchor="center")
table.column('e', width=60, anchor="center")
table.column('f', width=60, anchor="center")
table.column('g', width=60, anchor="center")
table.column('h', width=60, anchor="center")
table.column('i', width=60, anchor="center")
table.column('j', width=60, anchor="center")
table.heading('a', text='xx')
table.heading('b', text='xxx')
table.heading('c', text='xxxx')
table.heading('d', text='xxx')
table.heading('e', text='xx')
table.heading('f', text='xx')
table.heading('g', text='xxx')
table.heading('h', text='xxx')
table.heading('i', text='xxx')
table.heading('j', text='x')


top.mainloop()  # 父窗口进入事件循环,可以理解为保持窗口运行,否则界面不展示

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值