ashfaq_Aslam
ashfaq_Aslam

Reputation: 1

Tclerror: pyimage doesn't exist

from tkinter import *
from PIL import ImageTk,Image
app=Tk()

canvas=tk.Canvas(app,height=700,width=800)
canvas.pack()

im = Image.open('download.png')
ph = ImageTk.PhotoImage(im)
label1 = Label(app, image=ph)
label1.image=ph 

app.mainloop()

i seem to be getting a TclError saying pyimage doesnt exist, can anyone tell me why i tried using toplevel then there is no error but still there is no image, i also tried using a gif file without using PIL still there is no use

Upvotes: 0

Views: 804

Answers (2)

toyota Supra
toyota Supra

Reputation: 4537

You are missing pack.

label1 = Label(app, image=ph)
label1.pack()

Upvotes: 0

Jordan
Jordan

Reputation: 515

First of all you use wildcard import which is a bad practice. Next you call tk.Canvas which throws an error as you havent specified what tk is. If you want to load an image use canvas, not label. Here is the full code

import tkinter as tk
from PIL import ImageTk,Image


app = tk.Tk()
canvas = tk.Canvas(app,height=700,width=800)
canvas.pack()

im = Image.open('download.png')
ph = ImageTk.PhotoImage(im)
c = tk.Canvas(canvas)
c.pack()
c.create_image(0, 0, image=ph)

app.mainloop()

Upvotes: 1

Related Questions