从列表框中删除所选项目

时间:2017-04-01 16:42:25

标签: c# python listview tkinter listbox

我正在创建一个简单的GUI程序来管理优先级。

我已成功设法将项目添加到列表框中,但现在我需要将它们从列表框中以及从提供的列表中删除 - 因为,如果我错了,请更正我 - 在C#中创建在ListView中,您已经创建了ListView本身(屏幕上显示的对象),但您必须最终创建List<>从listview本身存储对象。我最近了解到END参数用于将项目附加到列表。这就像制作一个List<>在C#?

所以,现在我想从列表框中删除所选项目(如果需要,还要从列表中删除)。

我在这里:

# priorities.py
# GUI program to manage priorities

from tkinter import *

class GuiPart(Frame):

   def __init__(self, master):
       Frame.__init__(self, master)
       self.master = master
       self.master.resizable(width = False, height = False)
       self.master.title("Priorities")
       self.create_widgets()

   def create_widgets(self):

       buttonAdd = Button(self.master, text = "Add", command = self.addItem).grid(row = 2, column = 0, sticky = W + E)

       buttonRemove = Button(self.master, text = "Remove", command = self.removeItem).grid(row = 2, column = 1, sticky = W + E)

       buttonEdit = Button(self.master, text = "Edit", command = self.editItem).grid(row = 2, column = 2, sticky = W + E)

       self.listBox = Listbox(self.master, width=30)
       self.listBox.grid(row=1, sticky=W + E, columnspan=3)

       self.textBox = Text(self.master, height=10, width=30)
       self.textBox.grid(row=3, columnspan=3, sticky=W + E + N + S)

   def get_priority_subject(self):
       return self.textBox.get('1.0', '1.0 lineend')

   def get_priority_order(self):
       return self.textBox.get('2.0', '2.0 lineend')

   def addItem(self):
       self.listBox.insert(END, self.get_priority_subject()+'  '+ self.get_priority_order())
       self.clearAll()

   def removeItem(self):
       pass

   def editItem(self):
       pass

   def clearAll(self):
       self.textBox.delete('1.0', END)


if __name__ == "__main__":
    root = Tk()
    GuiPart(root)
    root.mainloop()

我使用的是Python 3.5。

0 个答案:

没有答案