The image does not show up when I run this Python code in Ubuntu

291 Views Asked by At

Is there something wrong with this code? It doesn't say there are any errors but the 'img' variable never shows at the end.

import Image
import ImageDraw

def main():
    b = 4
    size = 25
    fig_width = size
    fig_height = size

    white_rgb = (255, 255, 255)
    black_rgb = (0, 0, 0)
    img = Image.new("RGB", (fig_width, fig_height), white_rgb)
    draw = ImageDraw.Draw(img)

    for i in range(0, size, 5):
        for j in range(0, size, 5):
            if i % 2 == j % 2:
                draw.rectangle([(j, i), (j + b, i + b)], black_rgb)
    img.show()

main()
1

There are 1 best solutions below

2
On BEST ANSWER

PIL will try to use the ImageMagick display utility or xv to display images. If it cannot find either, it will fail silently. Try installing the imagemagick Ubuntu package and then run the script again.