0

I am trying to show the image using PIL and Tkinter but the image is not visible. It is occupying the area but the image is not there.

Here is my code and path to image is correct.

loadImage = Image.open(r'E:\Product\RAT\appimages\app_logo_splash.png')
renderImage = ImageTk.PhotoImage(loadImage)
imageLabel = Label(innerFrame, image=renderImage, bg=themeColor)
imageLabel.grid(row=0, column=0)

http://prntscr.com/jw89qg

When I am using this without creating a class then the image is showing but when I am putting this in a class and trying to access this image then the image is not showing

Kindly Help

Amit Sharma
  • 926
  • 2
  • 10
  • 35
  • 1
    Is this code on top-level, or within some function? My guess is that the image is being garbage-collected (yes, even though it's used in the Label). Try making the image `global`. See e.g. [this](https://stackoverflow.com/a/17761218/1639625) and many other related questions and answers. – tobias_k Jun 18 '18 at 10:06
  • @tobias_k i have added the code please check is am doing it right way or not – Amit Sharma Jun 18 '18 at 10:09
  • i am new for python – Amit Sharma Jun 18 '18 at 10:09
  • @tobias_k you will find the code in the link – Amit Sharma Jun 18 '18 at 10:10
  • 1
    Jup, that's the problem. Since you are using a class. best just do `self.renderimage = ...`. – tobias_k Jun 18 '18 at 10:13
  • It start working thanks for your answer , Please let me know why this is happing ? – Amit Sharma Jun 18 '18 at 10:14
  • As I said, the image is garbage collected as soon as the method is finished. The image being used by the label does not seem to hinder this, but why that's the case: I'd like to know, too. – tobias_k Jun 18 '18 at 10:17

0 Answers0