Home > Software design >  Why my os can't open a new window to show the image?
Why my os can't open a new window to show the image?

Time:09-17

I have setted the default application --gimp to open image in my os (debian 11 lxde).

enter image description here

The below python code will open the image in your default image viewer in so:
open a new window to show image

>>> from PIL import Image                                                                                
>>> img = Image.open('test.png')
>>> img.show() 

Why no new window opened and gimp start to show the image when executing in my os?

CodePudding user response:

To install matplotlib in Debian run sudo apt install python3-matplotlib. Use pyplot from the matplotlib Python module to display the image as follows.

import matplotlib.pyplot as plt
from PIL import Image
plt.imshow(Image.open('test.png'))
plt.show()

Alternatively install eog with sudo apt install eog and your original code will display the image in a new window. Please note that if the image is small then the new window will also be small, and you might not notice that it is open.

  • Related