Python Tkinter remove/delete Image from Label

Roman

I have a label with an image, and a button which should update the label / delete the image in the label, so I can put a new image into the same label via label.config.

I tryed to use something like that: whenever you click on the button the it should remove the image with label.config(image = None) but it doesnt work, if I load new images into the label the old ones are still there:

    # here is the label initialized 
    global brand_preview
    brand_preview = Label(root, image = None)
    brand_preview.place(x = 10, y = 60)

    # thats the button which have to clear the label image
    self.top_brand = Button(root, text = "clear", bg = "snow3", command=clear_label_image)
    self.top_brand.place(x = 550, y = 60)

    # thats how I load a photoimage into the label
    photoimg_brand = ImageTk.PhotoImage(im_thumb)
    brand_preview.image = photoimg_brand
    brand_preview.config(image = photoimg_brand)

    # Thats how the button works
    def clear_label_image():
        brand_preview.config(image = None)
        brand_preview.image = None

All I want now that if we I click the Button the brand_preview loses the image / the image gets deleted

EDIT: The main issue is solved, but that only works if the button only has to delete the image. If I want to delete and add a new one it doesnt work

def clear_label_image():
    brand_preview.config(image = "")
    photoimg_brand = ImageTk.PhotoImage(im_thumb)
    brand_preview.image = photoimg_brand
    brand_preview.config(image = photoimg_brand)
TigerhawkT3

You're very close - the image parameter just needs an empty string rather than None.

def clear_label_image():
    brand_preview.config(image='')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Python, Display openCv image in Tkinter in Label

View image from mysql DB file path on Tkinter label

Python: How to dynamically display image in label widget (tkinter)

Python tkinter - How to reload label's image every second?

How can I upload the selected image into the label with using python tkinter?

Python tkinter image label randomly displays some images but not others

Python tkinter label orientation

Python tkinter label formulas

Tkinter Python destroy label

For statement in label Python Tkinter

Label in python tkinter

Updating tkinter label image sequentially

Tkinter Label image without border

cannot associate image to tkinter label

Python tkinter Label set method with textvariable launched from another window

Python 3, Update label in Tkinter from different function?

Updating a label from an entry field on button push with tkinter in Python 3.5.2

Python Tkinter: Is there a way prevent 'Label' text from pushing columns to the side?

Suggestion on how to print result from function into a label field with Tkinter python

Python Tkinter: how to delete label from previous entry

Displaying Image from URL in python/Tkinter

How to display image in python Tkinter from url

Python 3 Tkinter appending label to print user input from entry label

Remove multiple label from tkinter

converting code from Tkinter TEXT to Tkinter LABEL

Python Tkinter TTK Separator With Label

update label variable in python tkinter

Python Tkinter Label Refresh Woes

Python constantly update label in tkinter