Python 使用tkinter combobox使用Treeview打印熊猫数据帧

Python 使用tkinter combobox使用Treeview打印熊猫数据帧,python,pandas,tkinter,combobox,treeview,Python,Pandas,Tkinter,Combobox,Treeview,我正在构建一个程序,允许用户从Tkinter Combobox菜单中选择一个选项,然后通过Treeview显示Pandas数据帧 以下是我的代码片段: def zip_mean_median(): global clean_df zipcodes_1 = clean_df.groupby([clean_df['ACTIVITY DATE'].dt.year, 'FACILITY ZIP'])['SCORE'].agg(['mean', 'median']) zipcode

我正在构建一个程序,允许用户从Tkinter Combobox菜单中选择一个选项,然后通过Treeview显示Pandas数据帧

以下是我的代码片段:

def zip_mean_median():
    global clean_df
    zipcodes_1 = clean_df.groupby([clean_df['ACTIVITY DATE'].dt.year, 'FACILITY ZIP'])['SCORE'].agg(['mean', 'median'])
    zipcodes_1_tree = ttk.Treeview(zipcodes_1)
    
fromlist_frame = ttk.LabelFrame(self.window, text="Statistics",relief=tk.RIDGE)
fromlist_frame.grid(row=2, column=2, sticky=tk.E + tk.W + tk.N + tk.S, padx=6)

combobox_label = tk.Label(fromlist_frame, text="Select one of the \n following options \n to print stats for \n ZIP Codes")
combobox_label.grid(row=2, column=1, sticky=tk.W + tk.N)

self.combobox_value = tk.StringVar()
my_combobox = ttk.Combobox(fromlist_frame, height=4, textvariable=self.combobox_value)
my_combobox.grid(row=2, column=2)
my_combobox['values'] = ("Mean & Median", "Mode")
my_combobox.current()
my_combobox.bind("Mean & Median", zip_mean_median)

但是,当我从组合框菜单中选择“平均值和中值”时,什么都没有发生。我缺少什么?

在tkinter中绑定事件时,您必须传递事件和回调函数,因此请尝试执行
my\u combobox.bind(“,zip\u mean\u median)