So far I have the ability to delete one or multiple listbox items from a listbox but i want to be able to delete those exact items from the actual list as well. If you run the code the code that I provided you will see that it is the opposite ended list item that is getting deleted. For example, if i highlight "14" and remove it, the item removed from the list is "0" since we have a range of (0,15). Please take a look, any feedback is appreciated.
import tkinter as tk
class Example(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title("Test Runner")
self.geometry("750x500")
self.resizable(width=False, height=False)
self.robot_files_ran_frame = tk.Frame(self)
self.robot_files_ran_frame.place(bordermode=tk.INSIDE, height=30, width=200, y=250, x=35)
self.display_robot_files_frame = tk.Frame(self, borderwidth=1, highlightthickness=1,
highlightbackground="black", highlightcolor="black")
self.display_robot_files_frame.place(bordermode=tk.INSIDE, height=200, width=300, y=285, x=50)
self.robot_file_list = tk.Listbox(self.display_robot_files_frame,selectmode=tk.MULTIPLE)
self.robot_file_list.place(bordermode=tk.INSIDE, height=196, width=296)
self.scroll_bar_x = tk.Scrollbar(self.robot_file_list, orient=tk.HORIZONTAL)
self.scroll_bar_x.config(command=self.robot_file_list.xview)
self.scroll_bar_x.pack(fill=tk.X, side=tk.BOTTOM)
self.robot_file_list.config(xscrollcommand=self.scroll_bar_x.set)
self.scroll_bar_y = tk.Scrollbar(self.robot_file_list, orient=tk.VERTICAL)
self.scroll_bar_y.config(command=self.robot_file_list.yview)
self.scroll_bar_y.pack(fill=tk.Y, side=tk.RIGHT)
self.robot_file_list.config(yscrollcommand=self.scroll_bar_y.set)
global some_list
some_list = []
for x in range(0,15):
some_list.append(x)
for y in some_list:
self.robot_file_list.insert(0, y)
self.remove_button = tk.Button(self, text= "Remove", height=2, width=6, command=self.remove_functionality)
self.remove_button.place(x=362, y=350)
def remove_functionality(self):
sel = self.robot_file_list.curselection()
# added reversed here so index deletion work for multiple selections.
for index in reversed(sel):
self.robot_file_list.delete(index)
del some_list[index]
print(some_list)
if __name__ == "__main__":
Example().mainloop()