Simple Listbox

Listbox, Label, Button

a very basic example, easy to follow, lets you select and delete members of a list box by pushing a button.

#TEST AREA - listbox,label, button
#standard set up header code 2 
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.configure(background='white')
scrW = root.winfo_screenwidth()
scrH = root.winfo_screenheight()  
workwindow = str(1024) + "x" + str(768)+ "+" +str(int((scrW-1024)/2)) + "+" +str(int((scrH-768)/2))
top1 = Toplevel(root, bg="light blue")
top1.geometry(workwindow)
top1.title("Top 1 - Workwindow")
top1.attributes("-topmost", 1)  # make sure top1 is on top to start
root.update()                   # but don't leave it locked in place
top1.attributes("-topmost", 0)  # in case you use lower or lift
#exit button - note: uses grid
b3=Button(root, text="Egress", command=root.destroy)
b3.grid(row=0,column=0,ipadx=10, ipady=10, pady=5, padx=5, sticky = W+N)
#____________________________

mylist=["item one", "item two", "item three", "item four", "item five"]

def initializeListBox():
    for item in mylist:
        listbox.insert(END, item)
def updateListBox(new,atnum):
    listbox.insert(atnum, new)
    top1.update()
def remove():
    listbox.delete(listbox.curselection())
        
invLF=LabelFrame(top1, width="2i", height="2i",bg="light blue")
invLF.grid(row=0, column=0)

listbox = Listbox(top1, font="arial 12")
listbox.grid(row=1,column=1)
listbox.insert(END, "A list entry") #listboxes are created empty so job 1 - fill them
initializeListBox()
updateListBox("item four and a half",4)

l1=Label(top1, text="Select one to remove:", bg="linen")
l1.grid( row=0, column=1)

b1=Button(top1, text="Remove", bg="yellow", fg="blue", command=remove)
b1.grid(row=0, column=2)

#____________________________
root.mainloop()