canvas_width = 512
canvas_height = 512
root = Tk()
canvas = Canvas(root, width=canvas_width, height=canvas_height)
canvas.pack()
canvas.create_rectangle(0, 0, canvas_width, canvas_height / 2, fill='green')
ps = canvas.postscript(colormode='color')
img = PIL.Image.open(io.BytesIO(ps.encode('utf-8')))
img.save("/home/test.png")
If you execute this code, you will see that the saved file, test.png
, contains only one black pixel. Instead, it should contain 512x256 green pixels and 512x256 undefined-color pixels.
Do you know why?