-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageTest.py
74 lines (50 loc) · 1.89 KB
/
ImageTest.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
from tkinter import *
from tkinter import filedialog
import os
def walk_dir(root_dir, extension):
file_list = []
towalk = [root_dir]
while towalk:
root_dir = towalk.pop()
for path in os.listdir(root_dir):
path = os.path.join(root_dir, path).lower()
for i in extension:
if os.path.isfile(path) and path.endswith(i):
file_list.append(path)
elif os.path.isdir(path):
towalk.append(path)
return file_list
root_dir = str(filedialog.askdirectory(title = "Select Location" ))
extension = ['.png']
image_list = walk_dir(root_dir, extension)
image_list.sort()
print(image_list)
def change(num,image_list):
global next_Button
global previous_Button
global canvas
global img
global my_label
my_label = Label(root,text = "Image " + str(num) + " of " + str(len(image_list)))
my_label.grid(row = 2 , column = 0 , columnspan = 3)
canvas = Canvas(root,width = 1360 , height = 620) # Canvas
previous_Button = Button(root,text = "< Previous", command = lambda : change(num-1,image_list))
next_Button = Button(root,text = "Next >", command = lambda : change(num+1,image_list))
canvas.grid_forget()
canvas.grid(row = 1, column = 0, columnspan = 3)
img = PhotoImage(file=(image_list[num-1]))
canvas.create_image(1,1, anchor=NW, image=img)
if num == len(image_list):
next_Button = Button(root, text = "Next >", state=DISABLED)
if num == 1:
previous_Button = Button(root, text="< Previous", state=DISABLED)
# Next button
next_Button.grid(row = 0, column = 1)
# Previous button
previous_Button.grid(row = 0, column = 0)
exit = Button(root,text = "Exit X" , command = lambda : quit()) # Exit Button
exit.grid(row = 0, column = 2)
root = Toplevel()
mastet = Canvas
change(1,image_list)
root.mainloop()