[PySimpleGUI] update listbox not working - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PySimpleGUI] update listbox not working (/thread-14022.html) |
[PySimpleGUI] update listbox not working - zappfinger - Nov-11-2018 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... RE: [PySimpleGUI] update listbox not working - zappfinger - Nov-12-2018 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' RE: [PySimpleGUI] update listbox not working - zappfinger - Nov-12-2018 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... |