Jul-21-2020, 06:11 PM
(This post was last modified: Jul-21-2020, 06:11 PM by Gribouillis.)
delphinis Wrote:_tkinter.TclErrorObserve that the error doesn't come from Python, it comes from the Tcl/Tk library upon which tkinter is sitting. This library may well accept only valid OS paths.
I'm not in the best position to answer, since I think a very good solution would be to get rid of the Windows OS...
More seriously, using the pathlib library to manipulate paths is a robust solution. Starting with Python 3.6, you can also use os.fspath, for example
import os from pathlib import Path filename = Path.cwd() / 'spam.png' astring = os.fspath(filename) # see if this returns a valid Windows pathIn good old python 1, 2, 3, one would have written
import os astring = os.path.join(os.getcwd(), 'spam.png')