from tkinter import *
window = Tk()
window.title('»çÁø ¾Ù¹ü')
window.geometry('500x300')
img_idx = 0
images = ['cat.png', 'dog.png', 'horse.png', 'rabbit.png']
length = len(images)
imgList = []
for image in images :
img = PhotoImage(file=image)
imgList.append(img)
lbl_img = Label(window, image = imgList[0])
lbl_img.pack()
lbl = Label(window, text=images[img_idx], font="¹ÙÅÁ 20 bold")
lbl.place(x=200, y=250)
def ShowL() :
global img_idx
if img_idx == 0 :
img_idx = length-1
else :
img_idx -= 1
lbl_img.configure(image=imgList[img_idx])
lbl.configure(text=images[img_idx])
def ShowR() :
global img_idx
if img_idx == length-1 :
img_idx = 0
else :
img_idx += 1
lbl_img.configure(image=imgList[img_idx])
lbl.configure(text=images[img_idx])
def KeyEvent(event) :
if event.char == '<' :
ShowL()
elif event.char == '>' :
ShowR()
window.bind("<Key>", KeyEvent)
btn1 = Button(window, text='<', command=ShowL)
btn1.place(x=50,y=100)
btn2 = Button(window, text='>', command=ShowR)
btn2.place(x=450,y=100)
window.mainloop()