-
Notifications
You must be signed in to change notification settings - Fork 0
/
carousel.py
57 lines (41 loc) · 1.59 KB
/
carousel.py
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
55
56
57
from tkinter import Tk, Label, Button
from PIL import Image, ImageTk
root = Tk()
root.title('Carousel')
img1 = ImageTk.PhotoImage(Image.open('img/img1.jpg'))
img2 = ImageTk.PhotoImage(Image.open('img/img2.jpg'))
img3 = ImageTk.PhotoImage(Image.open('img/img3.jpg'))
img4 = ImageTk.PhotoImage(Image.open('img/img4.jpg'))
img5 = ImageTk.PhotoImage(Image.open('img/img5.jpg'))
listImg = [img1, img2, img3, img4, img5]
lb = Label(root, image=img1)
lb.grid(row=0, column=0, columnspan=3)
def nextImg(imgNum):
global lb
global backBtn
global nextBtn
lb.grid_forget()
lb = Label(root, image=listImg[imgNum])
backBtn = Button(root, text='<-', command=lambda: backImg(imgNum - 1))
nextBtn = Button(root, text='->', command=lambda: nextImg(imgNum + 1))
if imgNum == 4: nextBtn = Button(root, text='-', state='disabled')
lb.grid(row=0, column=0, columnspan=3)
backBtn.grid(row=1, column=0)
nextBtn.grid(row=1, column=2)
def backImg(imgNum):
global lb
global backBtn
global nextBtn
lb.grid_forget()
lb = Label(root, image=listImg[imgNum])
backBtn = Button(root, text='<-', command=lambda: backImg(imgNum - 1))
nextBtn = Button(root, text='->', command=lambda: nextImg(imgNum + 1))
if imgNum == 0: backBtn = Button(root, text='-', state='disabled')
lb.grid(row=0, column=0, columnspan=3)
backBtn.grid(row=1, column=0)
nextBtn.grid(row=1, column=2)
backBtn = Button(root, text='-', state='disabled')
nextBtn = Button(root, text='->', command=lambda: nextImg(1))
backBtn.grid(row=1, column=0)
nextBtn.grid(row=1, column=2)
root.mainloop()