I’m working on a Tkinter application where the user can input a few fields before clicking on a button which is supposed to write what he wrote in a TreeView widget. This worked well when running on my mac, but on Windows, when calling insert() on the TreeView, I get a "builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 2570: invalid continuation byte".
I tried to call encode("utf-8") on the strings passed in the insert method, but this does not work.
for i in range(0, len(self.commandList)):
resumeTree.insert("", i, "", values = (self.commandList[i][0].encode("utf-8"), self.commandList[i][1].encode("utf-8"), self.commandList[i][2].encode("utf-8")), text = i)
My inputs may contain special caracter but the error is the same when I tried :
for i in range(0, len(self.commandList)):
resumeTree.insert("", i, "", values = ("a", "b", "c"), text = i)
Here is how my widget is defined :
resumeTree = ttk.Treeview(resumeFrame)
resumeTree['show'] = 'headings'
resumeTree["columns"]=("type","poids", "prix")
resumeTree.column("type", minwidth = 15, width = 200)
resumeTree.column("poids", minwidth = 75, width = 50)
resumeTree.column("prix", minwidth = 75, width = 50)
resumeTree.heading("type", text = "Type", anchor = tk.W)
resumeTree.heading("poids", text = "Poids (g)", anchor = tk.W)
resumeTree.heading("prix", text = "Prix total (euro)", anchor = tk.W)
resumeTree.Scrollable = True
Here is the backtrace of the error
File "C:\Users\Camille\Documents\GestionVentesClassique\main.py", line 165, in <module>
File "C:\Users\Camille\Documents\GestionVentesClassique\main.py", line 162, in main
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\tkinter\__init__.py", line 1283, in mainloop
self.tk.mainloop(n)
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\tkinter\__init__.py", line 1709, in __call__
self.widget._report_exception()
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\tkinter\__init__.py", line 1452, in _report_exception
root.report_callback_exception(exc, val, tb)
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\tkinter\__init__.py", line 2098, in report_callback_exception
traceback.print_exception(exc, val, tb)
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\traceback.py", line 104, in print_exception
type(value), value, tb, limit=limit).format(chain=chain):
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\traceback.py", line 508, in __init__
capture_locals=capture_locals)
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\traceback.py", line 363, in extract
f.line
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\traceback.py", line 285, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\linecache.py", line 47, in getlines
return updatecache(filename, module_globals)
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\linecache.py", line 137, in updatecache
lines = fp.readlines()
File "C:\Users\Camille\AppData\Local\Programs\Python\Python37-32\Lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 2582: invalid continuation byte