-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTkinter_Learning2.py
More file actions
85 lines (66 loc) · 3.12 KB
/
Tkinter_Learning2.py
File metadata and controls
85 lines (66 loc) · 3.12 KB
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
from tkinter import *
from PIL import ImageTk, Image
# Main Window
window = Tk()
window.title("Image Viewer")
window.iconbitmap('D:/Abdulloh/Inha University/Python Language/Auto School '
'Tkinter/icons/Wwalczyszyn-Android-Style-Honeycomb-Calculator.ico')
# Functions
def forward(img_num):
global my_label
global button_forward
global button_back
my_label.grid_forget()
my_label = Label(image=img_list[img_num-1])
button_forward = Button(window, text=">>", command=lambda: forward(img_num+1),
font=("times new roman", 15), bg="black", fg="white")
button_back = Button(window, text="<<",
font=("times new roman", 15), bg="black", fg="white",
command=lambda: back(img_num-1))
my_label.grid(row=0, column=0, columnspan=3)
button_back.grid(row=1, column=0)
button_forward.grid(row=1, column=2)
def back(img_num):
global my_label
global button_forward
global button_back
global status
my_label.grid_forget()
my_label = Label(image=img_list[img_num-1])
button_forward = Button(window, text=">>", command=lambda: forward(img_num+1),
font=("times new roman", 15), bg="black", fg="white")
button_back = Button(window, text="<<",
font=("times new roman", 15), bg="black", fg="white",
command=lambda: back(img_num-1))
status = Label(window, text="Image "+str(img_num) + " of " + str(len(img_list)), relief=SUNKEN, anchor=E,
font=("times new roman", 10))
status.grid(row=2, column=0, columnspan=3, sticky=W + E)
my_label.grid(row=0, column=0, columnspan=3)
button_back.grid(row=1, column=0)
button_forward.grid(row=1, column=2)
# Image
img1 = ImageTk.PhotoImage(Image.open("D:/Abdulloh/Inha University/Python "
"Language/Auto School Tkinter/images/bg1.jpg"))
img2 = ImageTk.PhotoImage(Image.open("D:/Abdulloh/Inha University/Python "
"Language/Auto School Tkinter/images/bg2.jpg"))
img3 = ImageTk.PhotoImage(Image.open("D:/Abdulloh/Inha University/Python "
"Language/Auto School Tkinter/images/bg3.jpg"))
img_list = [img1, img2, img3]
# Labels
my_label = Label(image=img1)
status = Label(window, text="Image 1 of " + str(len(img_list)), relief=SUNKEN, anchor=E,
font=("times new roman", 10))
# Button
button_quit = Button(window, text='Exit Program',
font=("times new roman", 15), command=window.quit, bg="black", fg="white")
button_back = Button(window, text="<<",
font=("times new roman", 15), bg="black", fg="white", command=back)
button_forward = Button(window, text=">>",
font=("times new roman", 15), bg="black", fg="white", command=lambda: forward(2))
# Showing on Window
my_label.grid(row=0, column=0, columnspan=3)
button_back.grid(row=1, column=0)
button_quit.grid(row=1, column=1)
button_forward.grid(row=1, column=2, pady=10)
status.grid(row=2, column=0, columnspan=3, sticky=W+E)
window.mainloop()