到目前为止,我有能力从列表框中删除一个或多个列表框项目,但我也希望能够从实际列表中删除那些确切的项目。如果您运行我提供的代码,您将看到它是被删除的相反端列表项。例如,如果我突出显示“14”并将其删除,则从列表中删除的项目是“0”,因为我们的范围是 (0,15)。请看一看,任何反馈表示赞赏。
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)
繁星coding
相关分类