How to add a list into a listbox in tkinter

This script shows how it is possible to put a list into a listbox, without having to iterate trough one, but just doing so:

  • create a list
  • add the list as value into StringVar (or IntVar)
  • add as listvariable argument the istance of StringVar
import tkinter as tk
import tkinter.ttk as ttk


root = tk.Tk()
root.geometry("400x400")
food_list = ['apple', 'banana', 'orange']
list1 = tk.StringVar(value=food_list)
lst = tk.Listbox(root,
	listvariable=list1)
lst.pack()

root.mainloop()
The window with the listbox that gets a list as items

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.