[Tkinter-discuss] update image on pressing button

Michael Lange klappnase at web.de
Wed Oct 29 20:20:45 CET 2014


Hi,

On Wed, 29 Oct 2014 13:08:04 +0530
rajat das <rajatdas2005 at gmail.com> wrote:

> Dear All,
> 
> I am new in python programming, kindly help me out.
> 
> *Problem:  *Basically as user press the "Next image button" the image
> should get refreshed by the next image from the specified path and so
> on. The problem is on pressing the button the image is coming below of
> the previous image not on top of it. Basically I want the images should
> slide on pressing the next button.
(...)
> def Click():
> 
>     image = Image.open("C:/Users/Slide2.bmp")
>     photo = ImageTk.PhotoImage(image)
> 
>     label = Label(root,image=photo)
>     label.image = photo # keep a reference!
>     label.pack()

the problem with your code is that instead of changing the image data of
the existing label widget you create a new Label. In your Click() function
you should simply do

    label.configure(image=photo)

instead of creating a new label.

I hope this helps

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Humans do claim a great deal for that particular emotion (love).
		-- Spock, "The Lights of Zetar", stardate 5725.6


More information about the Tkinter-discuss mailing list