小智 5
其实我已经找到解决办法了。分配列标题时,命令有一个 kwarg,因此代码可能如下所示:
import tkinter as tk # Tk
import tkinter.ttk as tkk # treeview
root = tk.Tk()
# create the Treeview
tv = ttk.Treeview(root)
tv['columns'] = ('a', 'b', 'c')
tv['show'] = 'headings' #remove "#0" column
# Add column headers and Click commands
tv.heading('a', text='header a', command=lambda: print('a is pressed!')
tv.heading('b', text='header b', command=lambda: print('b is pressed!')
tv.heading('c', text='header c', command=lambda: print('c is pressed!')
Run Code Online (Sandbox Code Playgroud)