0

I've created a function that responds to a button press. This function allows the user to look for an image file to upload into the application. Problem is, when the user wants to upload another image, the existing one stays behind and the new one is placed on top and so on and so fourth. How would I go about writing code to replace the old image with the new image, etc. I've thought this through and still cannot figure it out. I'm thinking maybe a global array? I'm stuck. Thanks

def importAlbumArt(self):
    # import mp3s only


    self.albumArt = askopenfilename(filetypes=[("JPEG Files", "*.jpeg"),("JPEG Files", "*.jpg"),("JPEG Files", "*.jif"),

                                            ("JPEG Files", "*.jfif"),("PNG Files", "*.png"),("GIF Files", "*.gif")])

    load = Image.open(self.albumArt)

    # place album art backdrop and change app status
    #self.albumFrame.place(x=self.editFrame.winfo_width()/75, y=self.editFrame.winfo_height()/50)
    self.status["text"] = "Album art imported"
    self.albumFrame.update()

    # resize image but maintain aspect ratio
    new_width = 250
    new_height = 250
    old_width = load.size[0]
    old_height = load.size[1]
    new_width = new_height * old_width/old_height
    new_height = new_width * old_height/old_width
    load = load.resize((int(new_width),int(new_height)), Image.ANTIALIAS)

    # render and place album art
    render = ImageTk.PhotoImage(load)
    img = (Label(self.editFrame, image=render))
    img.image = render
    img.grid(row=0, column=0, columnspan=2, rowspan=1)
terratunaz
  • 614
  • 3
  • 9
  • 19
  • have you searched this site for answers? There are many questions and answers related to images here. – Bryan Oakley Aug 05 '15 at 19:06
  • 1
    possible duplicate of [How to update the image of a Tkinter Label widget?](http://stackoverflow.com/questions/3482081/how-to-update-the-image-of-a-tkinter-label-widget) – TigerhawkT3 Aug 05 '15 at 19:07
  • 1
    because you create a new label each time the old one is never destroyed/cleared, you ought to have the label belong directly to the object, and use configure inside the method to set the picture. – James Kent Aug 05 '15 at 20:51
  • Thanks James!!! That's exactly where I went wrong. Your suggestion worked. – terratunaz Aug 05 '15 at 21:04

0 Answers0