I want to make a little app with Tkinter and it's about a photo viewer
There are 3 buttons on my Interface[Back , Exit , Forward], and the Exit button and the Forward button work good but unfortunately, I get some errors with the Back button
Forward Button: Move forward for the next photo Exit Button: Quit the app Back Button: Go back to the previous photo
Error is:
"button_back = Button(root, text = "<<", command = lambda: back(image_number-1)) TypeError: back() takes 0 positional arguments but 1 was given"
Code:
from Tkinter import *
from PIL import ImageTk, Image
my_img1 = ImageTk.PhotoImage(Image.open("one.png")) #-First Step
my_img2 = ImageTk.PhotoImage(Image.open("two.png"))
my_img3 = ImageTk.PhotoImage(Image.open("three.png"))
my_img4 = ImageTk.PhotoImage(Image.open("four.png"))
image_list = [my_img1, my_img2, my_img3, my_img4]
my_label = Label(image=my_img1) #Three Button
my_label.grid(row =0, column = 0, columnspan=3)
def back():
global my_label
global button_forward
global button_back
def forward(image_number):
global my_label
global button_forward
global button_back
my_label.grid_forget()
my_label = Label(image=image_list[image_number-1])
button_forward = Button(root, text = ">>", command =
lambda:forward(image_number+1))
#ERROR
button_back = Button(root, text = "<<", command = lambda: back(image_number-1))
my_label.grid(row =0, column = 0, columnspan=3)
button_back.grid(row= 1, column=0)
button_forward.grid(row = 1, column = 2)
button_back = Button(root, text = "<<", command = back)
button_forward = Button(root, text = ">>", command = lambda : forward(2))
button_exit = Button(root, text = "EXIT PROGRAM", command = root.quit)
button_back.grid(row= 1, column=0)
button_exit.grid(row = 1, column = 1)
button_forward.grid(row = 1, column = 2)
root.mainloop()