如何解决使用tkinter组合框选择作为df过滤器python
大家好,我是GUI python的新手。
我有一个窗口,用户可以从元素列表中选择一个元素,然后根据用户选择的元素,第二个list(crop)应该显示与该元素匹配的相应作物。
我尝试执行类似的操作,但是在农作物列表中,每个用户选择中仅显示“ []”。有人可以帮助我吗?谢谢
ele_list = pd.unique(np.append(df["elemnt"].unique (),(df_nir["elemnt"].unique())))
ele_list=",".join(ele_list)
ele_list=ele_list.replace(",","") #want to get the element list from db without "," and Apostrophes
crop_list=pd.unique(np.append(df["crop"].unique (),(df_nir["crop"].unique())))
Port=''
def calibration_window():
global cb_elemnt
top = tkinter.Toplevel (window)
top.title ("Calibration")
top.geometry ("400x400")
ttk.Label (top,text="Select an element:",font = ("Ariel",10)).grid (column=0,row=0)
cb_elemnt = ttk.Combobox (top,values=ele_list)
cb_elemnt.grid(column=0,row=1)
ttk.Label (top,text="Select a crop:",10)).grid (column=1,row=0)
cb_elemnt.bind("<<ComboboxSelected>>",set_port)
cb_crop=ttk.Combobox (top,values=pd.unique(df[df['elemnt'] == set_port]["crop"])) #according to user choise I filter the df to return crop tat match to the selected element
cb_crop.grid (column=1,row=1)
def set_port(_):
global Port
Port = cb_elemnt.get()
return Port
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。