-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_viewer.py
106 lines (70 loc) · 2.04 KB
/
image_viewer.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 25 18:28:37 2022
@author: ACER
"""
import glob
import tkinter as tk
from PIL import ImageTk, Image
img_list_raw = []
img_list = []
idx = [0]
window = tk.Tk()
window.geometry("800x400")
def img_finder():
""" Function to find images on Device """
for file in glob.glob("*.jpg"):
img_list_raw.append(file)
for file in glob.glob("*.png"):
img_list_raw.append(file)
for file in glob.glob("*.jpeg"):
img_list_raw.append(file)
for file in glob.glob("*.ico"):
img_list_raw.append(file)
for file in glob.glob("*.jfif"):
img_list_raw.append(file)
if img_list_raw:
return len(img_list_raw)
return None
TOTAL = img_finder()
img_list = img_list_raw
def img_loader():
""" Function to load the images on GUI"""
img = Image.open(img_list[idx[0]])
img = img.resize((300, 205), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
return img
def img_update(img):
""" Function to change the images based on user input """
label.config(image=img)
label.photo = img
def im_nxt():
""" Function for next Image """
if (idx[0] + 1) > TOTAL - 1:
pass
else:
idx[0] += 1
img_update(img_loader())
def im_prev():
""" Function for previous Image """
if (idx[0] - 1) < 0:
pass
else:
idx[0] -= 1
img_update(img_loader())
try:
frame = tk.Frame(window, width=600, height=600)
frame.pack()
frame.place(anchor='center', relx=0.5, rely=0.5)
current_img = img_loader()
label = tk.Label(frame, image=current_img)
label.pack()
B1 = tk.Button(window, text="Nxt", command=im_nxt)
B1.pack()
B1.place(anchor='e', relx=0.8, rely=0.5)
B2 = tk.Button(window, text="Prev", command=im_prev)
B2.pack()
B2.place(anchor='w', relx=0.2, rely=0.5)
window.mainloop()
except IndexError as e:
print(f"No images found -> {e}")