【发布时间】:2021-09-03 01:39:13
【问题描述】:
我想创建一个这样的表:
我希望它能够在我单击“删除此记录”时删除该行数据。我正在尝试这段代码:
from tkinter import *
from tkinter import ttk
def doAnything():
print("Do any thing")
ws = Tk()
ws.title('Help')
tv = ttk.Treeview(ws)
tv['columns'] = ('Rank', 'Name', 'Badge')
tv.column('#0', width=0, stretch=NO)
tv.column('Rank', anchor=CENTER, width=80)
tv.column('Name', anchor=CENTER, width=80)
tv.column('Badge', anchor=CENTER, width=80)
tv.heading('#0', text='', anchor=CENTER)
tv.heading('Rank', text='Id', anchor=CENTER, command=lambda: doAnything())
tv.heading('Name', text='rank', anchor=CENTER)
tv.heading('Badge', text='Badge', anchor=CENTER)
tv.insert(parent='', index=0, iid=0, text='',
values=('1', 'Vineet', 'delete this record'))
tv.insert(parent='', index=1, iid=1, text='',
values=('2', 'Anil', 'delete this record'))
tv.insert(parent='', index=2, iid=2, text='',
values=('3', 'Vinod', 'delete this record'))
tv.insert(parent='', index=3, iid=3, text='',
values=('4', 'Vimal', 'delete this record'))
tv.insert(parent='', index=4, iid=4, text='',
values=('5', 'Manjeet', 'delete this record'))
tv.pack(fill=BOTH, expand=True)
ws.mainloop()
【问题讨论】:
-
好的,很酷。这段代码怎么不能做你想做的事?请阅读How to Ask。
标签: python tkinter tkinter-layout