Introduction

In this article, I will explain how to add a listbox in Tkinter in Python.
Definition
The Listbox keyword is used to display a list of items from which a user can select a number of items in the listbox.
Syntax
  1. w = Listbox( a, option)
Parameters
a − This represents the parent window of the computer.
option − The list of most used options for this widget.
Option & Description
Program
  1. from tkinter import *
  2. a= Tk()
  3. a.geometry("400x400")
  4. a.title("test")
  5. Lb1 = Listbox(a,bg = "pink", bd = 10, fg = "black",\
  6. font = "Castellar", cursor = "target")
  7. Lb1.insert(1, "lion")
  8. Lb1.insert(2, "tiger")
  9. Lb1.insert(3, "zebra")
  10. Lb1.insert(4, "elephant")
  11. Lb1.insert(5, "deer")
  12. Lb1.insert(6, "fox")
  13. Lb1.insert(7, "Wolf")
  14. Lb1.insert(8, "Gorilla")
  15. Lb1.insert(9, "Jackal")
  16. Lb1.insert(10, "Otter")
  17. Lb1.pack()
  18. a.mainloop()
Output
How To Add  Listbox In Tkinter In Python
Program
  1. from tkinter import *
  2. a= Tk()
  3. a.geometry("400x400")
  4. a.title("test")
  5. listbox1=Listbox(a, background="yellow", fg="black",
  6. highlightbackground="blue",highlightthickness=10,
  7. selectbackground="green",highlightcolor="red")
  8. listbox1.grid(row=1, column=1)
  9. for x in range(1, 10):
  10. listbox1.insert(END, x)
  11. a.mainloop()
Output
How To Add  Listbox In Tkinter In Python
Program
  1. from tkinter import *
  2. a=Tk()
  3. a.title("scrollbar")
  4. list_one=Listbox(a,width=20,height=20,
  5. justify=CENTER,bg="orange",bd=20)
  6. scroll_one=Scrollbar(a,command=list_one.yview)
  7. list_one.configure(yscrollcommand=scroll_one.set)
  8. list_one.pack(side=LEFT)
  9. scroll_one.pack(side=RIGHT,fill=Y)
  10. for i in range(100):
  11. list_one.insert(END,i)
  12. a.mainloop()
Output
How To Add  Listbox In Tkinter In Python

Conclusion

In this article, we have seen how to add a listbox in Tkinter in Python. I hope this article was useful to you. Thanks for reading!