1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 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() | cs |