Home>

Please write the details of your question here.
(Example) I am making a ●● system with PHP (CakePHP).
■■ The following error message occurred while implementing the function.

Error message

couldn't recognize data in image file

Corresponding source code

import tkinter
root = tkinter.Tk ()
root.title ("Madao Diagnostic App")
root.resizable (False, False)
canvas = tkinter.Canvas (root, width = 800, height = 600)
canvas.pack ()
gazou = tkinter.PhotoImage (file = "a.png")
canvas.create_image (400,300, image = gazou)

root.mainloop ()

Source code
What I tried

The image cannot be displayed with JPN
Converted from JPN format to PNG
Please describe here what you have tried for the problem.

Supplementary information (FW/tool version, etc.)

I can't tell you well because I've just started, but please teach me.
Please provide more detailed information here.

  • Answer # 1

    Combined with Pillow (the successor to PIL), you can view Jpeg images in tkinter.

    import tkinter
    from PIL import Image, ImageTk
    root = tkinter.Tk ()
    root.title ("Madao Diagnostic App")
    root.resizable (False, False)
    canvas = tkinter.Canvas (root, width = 800, height = 600)
    canvas.pack ()
    image = Image.open ("a.jpg")
    gazou = ImageTk.PhotoImage (image)
    canvas.create_image (400, 300, image = gazou)
    root.mainloop ()