listbox = Listbox(master, selectmode=SINGLE) # SINGLE表示只能单选
listbox.pack(fill=BOTH, expand=True, padx=10, pady=10)
# 定义要添加的习惯列表
habits = ["勤于动笔", "高傲自大", "随手丢垃圾", "粗心大意", "专心听讲"]
# 使用for循环将习惯添加到列表中
for habit in habits:
listbox.insert(END, habit)
# 定义删除选中项的函数
def delete_selected():
# 获取选中项的索引
selected_index = listbox.curselection()
if selected_index: # 检查是否有选中项
listbox.delete(selected_index)