Below is PySimpleGUI code to create a multilanguage dictionary where I can add entries for each word in different languages, and also have the possibility to search by language. Unfortunately, I got the following error:
AttributeError: 'list' object has no attribute 'tree_dict'
How can I fix this?
import sqlite3
import PySimpleGUI as sg
# Create connection to SQLite database
conn = sqlite3.connect('Data_Enteries.db')
c = conn.cursor()
# Create table if it doesn't exist
c.execute('''CREATE TABLE IF NOT EXISTS dictionary
(id INTEGER PRIMARY KEY,
English TEXT,
French TEXT,
Spanish TEXT,
Chinese TEXT,
Swedish TEXT,
Turkish TEXT)''')
conn.commit()
# Create PySimpleGUI layout
layout = [[sg.Text('Enter word to search: '), sg.InputText(key='search'),
sg.Button('Search')],
[sg.Tree(data=[], headings=['English', 'French', 'Spanish', 'Chinese', 'Swedish',
'Turkish'], key='treeview', col_widths=[20]*6)]]
# Create PySimpleGUI window
window = sg.Window('Multilanguage Dictionary', layout)
# Function to retrieve data from database
def search_database(word):
# Execute SELECT query
c.execute('''SELECT * FROM dictionary
WHERE English = ? OR
French = ? OR
Spanish = ? OR
Chinese = ? OR
Swedish = ? OR
Turkish = ?''', (word, word, word, word, word, word))
results = c.fetchall()
# Convert results to PySimpleGUI treeview data format
data = []
for row in results:
data.append([row[1], row[2], row[3], row[4], row[5], row[6]])
return data
# Loop to handle PySimpleGUI events
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
if event == 'Search':
search_word = values['search']
tree_data = search_database(search_word)
window['treeview'].update(values=tree_data)
# Close PySimpleGUI window and SQLite database connection
conn.close()
window.close()
Traceback:
C:\UsersUserName\Desktop>MultiLangPSG.py
Traceback (most recent call last):
File "C:\UsersUserName\Desktop\MultiLangPSG.py", line 47, in <module>
event, values = window.read()
^^^^^^^^^^^^^
File "C:\UsersUserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 10075, in read
results = self._read(timeout=timeout, timeout_key=timeout_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\UsersUserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 10146, in _read
self._Show()
File "C:\UsersUserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 9886, in _Show
StartupTK(self)
File "C:\UsersUserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 16866, in StartupTK
_convert_window_to_tk(window)
File "C:\UsersUserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 16753, in _convert_window_to_tk
PackFormIntoFrame(window, master, window)
File "C:\UsersUserName\AppData\Local\Programs\Python\Python311\Lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 16402, in PackFormIntoFrame
for key, node in element.TreeData.tree_dict.items():
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'tree_dict'