May 2019
Intermediate to advanced
542 pages
13h 37m
English
A significant problem with using image files in a program is making sure the program can find them at runtime. Paths passed into a QPixmap constructor or a QIcon constructor are interpreted as absolute (that is, if they begin with a drive letter or path separator), or as relative to the current working directory (which you cannot control). For example, try running your script from somewhere other than the code directory, as follows:
$ cd ..$ python ch05/game_lobby.py
You'll find that your images are all missing! QPixmap does not complain when it cannot find a file, it just doesn't show anything. Without an absolute path to the images, you'll only be able to find them if the script is run from the exact directory to ...
Read now
Unlock full access