In Python strings, \
is escape character that is used for special characters like new-line (\n
), tab (\t
), etc. In your second path, "images\nuke.png"
, you have \n
so it is parsed as "images<new-line>uke.png"
and PyQt can't find that file.
You have a couple of options:
- You can escape the
\
itself:"images\\nuke.png"
- You can use a raw string, which disables escaping:
r"images\nuke.png"
- You can use
/
for folder separator:"images/nuke.png"
I prefer third option. Windows accepts both \
and /
for folder separator. Besides in Qt, using /
is the preferred way since it is automatically translated to the appropriate system separator:
Qt uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs. If you always use "/" as a directory separator, Qt will translate your paths to conform to the underlying operating system.