tkinter - 从组合框选择值会重置另一个列表框的值
我有一个下拉框和一个列表框,像这样:
cities = df[df.columns[0]].tolist()
city_frame = tk.Frame(root)
city_frame.grid(row=1, column=1, sticky=tk.N)
cities_var = tk.Variable()
cities_var.set(cities)
tk.Label(city_frame, text="Thành phố").grid(row=0, column=0)
selected_cities_lb = tk.Listbox(
city_frame, height=20, listvariable=cities_var, selectmode=tk.MULTIPLE
)
selected_cities_lb.grid(row=1, column=0)
plot_types = ['parallel coordinate', 'stacked bar chart', 'grouped bar chart']
plot_type_frame = tk.Frame(root)
plot_type_frame.grid(row=1, column=2, sticky=tk.N)
plot_type_var = tk.StringVar()
plot_type_var.set(plot_types[0])
tk.Label(plot_type_frame, text="Loại biểu đồ").grid(row=0, column=0)
selected_plot_type_lb = ttk.Combobox(
plot_type_frame, textvariable=plot_type_var, values=plot_types, state='readonly')
selected_plot_type_lb.grid(row=1, column=0)
但是有一个问题:当我从下拉框中选择任何值时,列表框中所有选中的值都会被取消,这让人很烦恼。有人知道这是怎么回事吗?因为在我看来,它们之间根本没有关系。
1 个回答
1
加上 exportselection=False
这个设置就解决了这个问题。