-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (50 loc) · 1.93 KB
/
main.py
File metadata and controls
67 lines (50 loc) · 1.93 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
import argparse
import os, sys
import tkinter as tk
from PIL import ImageTk, Image
class Application(tk.Frame):
def __init__(self, master=None, imgPath=""):
super().__init__(master)
self.imgPath = imgPath
self.multiple = os.path.isdir(imgPath)
self.pos = 0
if self.multiple:
self.imgList = os.listdir(imgPath)
else:
self.imgList = [imgPath]
self.pack()
self.create_widgets()
def create_widgets(self):
if self.multiple:
self.img = ImageTk.PhotoImage(Image.open("{}{}".format(self.imgPath, self.imgList[0])))
else:
self.img = ImageTk.PhotoImage(Image.open("{}".format(self.imgPath)))
self.imgPanel = tk.Label(image = self.img)
self.imgPanel.pack(side="top")
self.name = tk.Label(self)
self.name["textvariable"] = str(self.imgList[0])
self.name.pack(side="top")
if self.multiple:
self.prev = tk.Button(self)
self.prev["text"] = "<"
self.prev["command"] = lambda: self.update_img(-1)
self.prev.pack(side="left")
self.next = tk.Button(self)
self.next["text"] = ">"
self.next["command"] = lambda: self.update_img(1)
self.next.pack(side="right")
def update_img(self, dir):
self.pos = (self.pos + (1 * dir)) % len(self.imgList)
img = self.imgList[self.pos]
print("Loading Image: {}".format(str(img)))
self.img = ImageTk.PhotoImage(Image.open("{}{}".format(self.imgPath, img)))
self.imgPanel.configure(image = self.img)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("path", help="file location of img")
args = parser.parse_args()
root = tk.Tk()
root.title("Pimg - Python IMG viewer")
root.geometry("600x400")
app = Application(master=root, imgPath=args.path)
app.mainloop()