Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Visiting Card Scanner GUI Application using Python
Next article icon

In this article, we will create a slideshow application i.e we can see the next image without changing it manually or by clicking. 

Modules Required:

  • Tkinter: The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI toolkit.
  • Pillow: The Python Imaging Library adds image processing capabilities to your Python interpreter. This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities. It can be installed using the below command:
pip install Pillow

Step-by-step Approach:

  • Firstly we have to import the modules.
Python3
# import required modulesimporttkinterastkfromtkinterimport*fromPILimportImagefromPILimportImageTk
  • Load the images.
Python3
# adjust windowroot=tk.Tk()root.geometry("200x200")# loading the imagesimg=ImageTk.PhotoImage(Image.open("photo1.png"))img2=ImageTk.PhotoImage(Image.open("photo2.png"))img3=ImageTk.PhotoImage(Image.open("photo3.png"))l=Label()l.pack()
  • Now we have to make a function calledmove to make the image move(It here means that one image appears and after a movement, it disappears.
Python3
# using recursion to slide to next imagex=1# function to change to next imagedefmove():globalxifx==4:x=1ifx==1:l.config(image=img)elifx==2:l.config(image=img2)elifx==3:l.config(image=img3)x=x+1root.after(2000,move)# calling the functionmove()
  • Now we have to just call the mainloop function of tkinter to end the task.
Python3
root.mainloop()
  • Whole Code=
Python3
# import required modulesimporttkinterastkfromtkinterimport*fromPILimportImagefromPILimportImageTk# adjust windowroot=tk.Tk()root.geometry("200x200")# loading the imagesimg=ImageTk.PhotoImage(Image.open("photo1.png"))img2=ImageTk.PhotoImage(Image.open("photo2.png"))img3=ImageTk.PhotoImage(Image.open("photo3.png"))l=Label()l.pack()# using recursion to slide to next imagex=1# function to change to next imagedefmove():globalxifx==4:x=1ifx==1:l.config(image=img)elifx==2:l.config(image=img2)elifx==3:l.config(image=img3)x=x+1root.after(2000,move)# calling the functionmove()root.mainloop()

Output:


Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp