Inserting an image with tkinter
Solved
Neirdah
-
Neirdah -
Neirdah -
Bonjour,
I am trying to program the insertion of an image using tkinter but each time I get the error 'TclError: image "pyimage5" doesn't exist'. I would like to know what is wrong with my code.
Configuration: Windows / Edge 87.0.664.75
I am trying to program the insertion of an image using tkinter but each time I get the error 'TclError: image "pyimage5" doesn't exist'. I would like to know what is wrong with my code.
class Interface(Tk): def __init__(self, path_image): super(Interface, self).__init__() self.image = PhotoImage(file=path_image) self.w, self.h = self.image.width(), self.image.height() self.canvas = Canvas(self, width=self.w, height=self.h) self.canvas.pack() self.canvas.create_image((self.w//2, self.h//2), image=self.image) self.mainloop() Interface(r"C:\Users\lbhad\OneDrive\Documents\BCPST\2\Informatique\logo2.png")
Configuration: Windows / Edge 87.0.664.75
4 answers
Hello Neirdah,
So, are you having success?
I did this and it works:
So, are you having success?
I did this and it works:
# -*- coding:Latin-1 -*- from tkinter import * class Interface(Tk): def __init__(self, path_image): super(Interface, self).__init__() self.image = PhotoImage(file=path_image) self.w, self.h = self.image.width()+10, self.image.height()+10 self.canvas = Canvas(self, width=self.w, height=self.h) self.canvas.pack() self.canvas.create_image(self.w//2, self.h//2, image=self.image) self.mainloop() Interface(r"C:\Phil\Dev\Python\tests\ccm\images\Fresque_01.png")