Click here to Skip to main content
14,775,228 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
from tkinter import *
from PIL import ImageTk, Image

root = Tk()
root.title("experiment")

my_img1 = ImageTk.PhotoImage(file="C:/Users/csneb/Desktop/Background/de_files/imagine.png")
my_img2 =  ImageTk.PhotoImage(file="C:/Users/csneb/Desktop/Background/de_files/img2.png")
my_img3 =  ImageTk.PhotoImage(file="C:/Users/csneb/Desktop/Background/de_files/img3.jpg")
my_img4 =  ImageTk.PhotoImage(file="C:/Users/csneb/Desktop/Background/de_files/img4.jpg")
my_img5 =  ImageTk.PhotoImage(file="C:/Users/csneb/Desktop/Background/de_files/img5.jpg")

image_list = [my_img1, my_img2, my_img3, my_img4, my_img5]
#.configure(image=image_list[number])
my_label = Label(image=my_img1)
my_label.grid(row=0, column = 0, columnspan = 3)


def forward(image_number):
    global my_label
    global button_forward
    global button_back 
    my_label.grid_forget()
    my_label = Label(image_list[image_number-1])
    button_forward = Button (root, text=">>", command=lambda: forward(image_number+1))
    button_back = Button(root, text="<<", command = lambda: back(image_number-1))
    my_label.grid(row=0, column = 0, columnspan = 3)
    button_forward.grid(row=1, column=2)
    button_back.grid(row=1, column=0)

def back():
    global my_label
    global button_forward
    global button_back 

button_back = Button(root, text="<<", command = back)
button_exit = Button(root, text="exit", command = root.quit)
button_forward = Button(root, text=">>", command = lambda: forward(2))

button_back.grid(row=1, column=0)
button_exit.grid(row =1, column = 1)
button_forward.grid(row=1, column=2)

root.mainloop()


What I have tried:

It's shows me this:
https://ibb.co/kXRtnFm
But when i press >> shows me this:
https://ibb.co/b7SRCkj
Instead of another image.

I saw this guy's tutorial, i tried to do what he does, but my program don't show me the next image: https://www.youtube.com/watch?v=zg4c92pNFeo[^]

CAN YOU HELP ME PLEASE? THANK YOU VERY MUCH!!!!!
Posted
Updated 28-Dec-20 1:00am
Comments
Richard MacCutchan 26-Dec-20 3:54am
   
I think you are overwriting the image with the buttons, although I am struggling to follow the logic in that code. I suggest you ask the person who created the tutorial.

BTW, please do not write in all capitals. That is read as shouting on the internet, and is considered rud.

1 solution

You are missing the Label function argument 'image'. You have written it as:
my_label = Label(image_list[image_number-1])
It should be like this:
my_label = Label(image = image_list[image_number-1])
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900