Python Forum

Full Version: [PySimpleGUI] update listbox not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to update a listbox in PySimpleGUI.I have a listbox with a key, so I use this code:
test=['aaaa','bbbb','cccc']
window.FindElement('_OUTPUT_').Update(values=test)
I get this error:
window.FindElement('_OUTPUT_').Update(values=test)
File "/Users/richard/anaconda/lib/python3.5/site-packages/PySimpleGUI/PySimpleGUI.py", line 719, in Update
self.TKListbox.delete(0, 'end')
AttributeError: 'NoneType' object has no attribute 'delete'

It is as if the listbox with '_OUTPUT_' key is not found...
Here is the full code:
import PySimpleGUI as sg
from SQLiteClient import *

##########################
name = 'Pi3B+'
##########################
conf = db()
otherIP = conf.select('select IP from nodes where name="%s" ' % name)[0][0]
layout = [
	[sg.Listbox(values=[], key='_OUTPUT_', size=(30, 6))],
    [sg.Submit(), sg.Cancel()]
     ]
window = sg.Window('ToDo').Layout(layout)
clint = client(otherIP, 8889)
clint.sendSQL('select first_name from employees')
ret = clint.checkQ()
print(ret)

test=['aaaa','bbbb','cccc']
window.FindElement('_OUTPUT_').Update(values=test)
button, values = window.Read()
And here is the output:
/Users/richard/anaconda/bin/python3.5 /Users/richard/PycharmProjects/ToDo/todos.py
config.sqlite
config.sqlite
SQLiteClient clienting on ('0.0.0.0', 8889)
[['Jim'], ['Jim'], ['Jim'], ['John'], ['Susan']]
Traceback (most recent call last):
File "/Users/richard/PycharmProjects/ToDo/todos.py", line 24, in <module>
window.FindElement('_OUTPUT_').Update(values=test)
File "/Users/richard/anaconda/lib/python3.5/site-packages/PySimpleGUI/PySimpleGUI.py", line 719, in Update
self.TKListbox.delete(0, 'end')
AttributeError: 'NoneType' object has no attribute 'delete'
Apparently I had to use Finalize() on the layout line, like this:
window = sg.Window('ToDo').Layout(layout).Finalize()

Since the window is not fully formed until then...