[Tkinter-discuss] update image on pressing button

rajat das rajatdas2005 at gmail.com
Wed Oct 29 08:38:04 CET 2014


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. I am sharing my code for understanding. You
need few "bmp" files and set the path according to which path need to set
in the program.

====================================================
from Tkinter import *
from PIL import Image, ImageTk

root = Tk()

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()



image = Image.open("C:/Users/Slide1.bmp")
photo = ImageTk.PhotoImage(image)
label = Label(root,image=photo)

label.image = photo # keep a reference!
label.pack()


labelframe = LabelFrame(root)
labelframe.pack(fill="both", expand="yes")


left = Label(labelframe)

button=Button(labelframe, padx = 5, pady = 5, text="Next",command = Click)
button.pack(side = RIGHT)


R1 = Radiobutton(labelframe, text="Choice 1", value=1)
R1.pack(side = LEFT)

R2 = Radiobutton(labelframe, text="Choice 2",  value=2)
R2.pack(side = LEFT)


left.pack()
root.mainloop()

============================================

-- 
Thanks
Rajat Das
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20141029/a9fbf996/attachment.html>


More information about the Tkinter-discuss mailing list