how to switch image in tkinter? making it mutable? how?

Jeff Hobbs jeff.hobbs at gmail.com
Mon Aug 16 12:57:47 EDT 2010


On Aug 16, 7:30 am, ChrisChia <chrischi... at gmail.com> wrote:
> I have this:
> image1 = ImageTk.PhotoImage(file = "c:\\f1.jpg")
> image2 = ImageTk.PhotoImage(file = "c:\\f2.jpg")
>
> imagelist.append(image1)
> imagelist.append(image2)
>
> self.label  = tk.Label(image = imagelist[0])
>
> is there a way that i can create a method to switch the display the
> image2 (imagelist 2nd element)
> without using label.bind?
>
> can i make an image mutable?

self.label.configure(image = imagelist[1]) will change the image
displayed.
With PIL images, you can use image1.fromstring(...) that should have a
similar effect, in that it changes the underlying image data and the
label will display that.

Whether you need to label.bind or something else to effect this change
is up to you.  You could have it happen on a timer, triggered by an
event, or randomly effected by solar flares, depending on your
application's needs.

Jeff



More information about the Python-list mailing list