I would like my Listbox widget to be updated upon clicking of a button. However I encountered a logic error. When I click on the button, nothing happens. No errors at all.
listOfCompanies: [[1, ''], [2, '-'], [3, '@ASK TRAINING PTE. LTD.'], [4, 'AAIS'], [5, 'Ademco'], [6, 'Anacle']def populatebox():listBox.insert("end", listOfCompanies)btn = Button(self, text="Update list", command = lambda: populatebox())
btn.pack()
If you're looking to just insert every tuple
into the Listbox
from the list
as they are without separating out the tuple
then there are two major changes.
First you cannot declare a list as list: [1, 2, 3, ...]
, it must be list = [1, 2, 3, ...]
.
Secondly, you are currently attempting to insert the entire list
onto one entry in the Listbox
. You should instead iterate over them, see below for an example:
from tkinter import *root = Tk()listBox = Listbox(root)
listBox.pack()listOfCompanies = [[1, ''], [2, '-'], [3, '@ASK TRAINING PTE. LTD.'], [4, 'AAIS'], [5, 'Ademco'], [6, 'Anacle']]def populatebox():for i in listOfCompanies:listBox.insert("end", i)btn = Button(root, text="Update list", command = lambda: populatebox())
btn.pack()