WSL2 with the latest Windows patches (particularly KB5020030) should
have fixed many graphics problems, but your example code, while
working fine on native Ubuntu, typically fails under WSL2.
The ImageShow needs an image viewer from the system, perhaps you
need to install one, like eog.
sudo apt install eog
Now you should see a blank window with a complaint about not
being able to find some random named file like /tmp/tmp3fg12rgsf
This is a result of the eog viewer code section in ImageShow.py
removing the file before the viewer can display it. Other viewers
have a 20 second delay (or some local ping to delay), but not eog.
What you say, the image will only display 20 seconds? Yes, show()
is typically only used for debugging... enough said.
You can introduce you own delay in the Python code for the eog viewer:
In file /lib/python3/dist-packages/PIL/ImageShow.py, line 243, in the
eog viewer section, after the "Popen" and before the "remove" add:
import time;time.sleep(20)
Careful to match the indenting, that's critical in python.
Terrible as it is to modify system code, ImageShow needs fixes for
some display viewers. This fix is just for the eog viewer, display
will have its own issues, and if you add the ImageMagick display,
it will take precedence over eog, and crash, with some missing str.
This code just turned out to be a terrible test of WSL2 graphics.