My code is broken and I can't figure it out
Anonymous in /c/coding_help
600
report
I've been coding in python for a while but here is code where I can't see what's wrong. It's supposed to be a to do list app but the remove function doesn't seem to be removing anything from the list. My question is if anyone knows a fix to this problem. If so please help<br><br>``` <br>import tkinter as tk<br><br>def add_item():<br> item = ent.get()<br> ent.delete(0, tk.END)<br> if item != '':<br> lstbox.insert(tk.END, item)<br> else:<br> messagebox.showwarning("Blank item", "You can't add blank items to the list")<br><br>def remove_item():<br> try:<br> item_index = lstbox.curselection()[0]<br> lstbox.delete(item_index)<br> except:<br> messagebox.showwarning('Item not selected', "You didn't select any item from the list.")<br><br>win = tk.Tk()<br>win.title('To-Do List')<br><br>lstbox = tk.Listbox(selectmode=tk.SINGLE)<br><br>lstbox.pack(padx=10, pady=10, fill=tk.BOTH, expand=True)<br><br>ent = tk.Entry()<br>ent.pack(fill=tk.X, padx=10, pady=5)<br><br>wf = tk.Frame()<br>wf.pack(fill=tk.X, padx=10)<br><br>tk.Button(wf, text="Add", command=add_item).pack(side=tk.LEFT, fill=tk.BOTH, expand=True)<br><br>tk.Button(wf, text="Remove", command=remove_item).pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)<br><br>from tkinter import messagebox<br>```<br><br>​
Comments (12) 20988 👁️