Python‎ > ‎tkinter‎ > ‎

tkinter.Listbox


Definition
Construct a listbox widget with the parent MASTER.

Syntax
tkinter.Listbox
Listbox()

Options
Listbox(background, bd, bg, borderwidth, cursor, exportselection, fg, font, foreground, height, highlightbackground, highlightcolor, highlightthickness, relief, selectbackground, selectborderwidth, selectforeground, selectmode, setgrid, takefocus, width, xscrollcommand, yscrollcommand, listvariable.)


Examples
The Listbox is created through for loop.
from tkinter import*
 
master=Tk()
master.title("Listbox")

listbox=Listbox(master, background="Blue", fg="white",selectbackground="Red",highlightcolor="Red")
listbox.grid(row=1, column=1)

for x in range(1, 10):

    listbox.insert(END, x)

master.mainloop()





The code created the Listbox and insert the values in it.
from tkinter import*

x = Tk()
y=Listbox(x)
y.pack()

y.insert(END, "Listbox")

for names in ["Adil", "John", "Eric", "Edward"]:
    y.insert(END, names)

    if names=="Adil":
        y.insert(END,"Erica")
                         
mainloop()





tkinter


Comments