-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
130 lines (107 loc) · 4.7 KB
/
gui.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from Tkinter import Tk, Button, Label, Text, Entry, Radiobutton, mainloop
from PIL import Image, ImageTk
class Gui:
Button = Button
Label = Label
Text = Text
Entry = Entry
Radiobutton = Radiobutton
def __init__(self):
self.root = Tk()
self.height = None
self.width = None
def changeentry(self, row, column, text, types=Label, callback=False, callname=None):
if types is Button and callback:
Button(self.root, text=text, command=callname).grid(row=row, column=column)
else:
types(self.root, text=text).grid(row=row, column=column)
def image(self, row, column, image, thumnail=False, thumbwidth=32, thumbheight=32):
try:
fin = Image.open(image)
except Exception:
try:
fin = Image.open(image)
except Exception:
Gui.settitle("Image Error")
if thumnail:
fin.thumbnail((thumbwidth, thumbheight), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(fin)
im = Label(self.root, image=photo)
im.image = photo
im.grid(row=row, column=column)
def rawimage(self, row, column, rawimage, thumnail=False, thumbwidth=32, thumbheight=32):
try:
fin = Image.eval(rawimage)
except Exception:
Gui.settitle("Image Error")
if thumnail:
fin.thumbnail((thumbwidth, thumbheight), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(fin)
im = Label(self.root, image=photo)
im.image = photo
im.grid(row=row, column=column)
@staticmethod
def returnrawimage(rawimage, thumnail=False, thumbwidth=32, thumbheight=32):
fin = Image.eval(rawimage)
if thumnail:
fin.thumbnail((thumbwidth, thumbheight), Image.ANTIALIAS)
return str(ImageTk.PhotoImage(fin))
@staticmethod
def returnimage(image, thumbnail=False, thumbwidth=32, thumbheight=32):
fin = Image.open(image)
if thumbnail:
fin.thumbnail((thumbwidth, thumbheight), Image.ANTIALIAS)
return ImageTk.PhotoImage(fin)
def setgridsize(self, height=5, width=6):
self.height = height
self.width = width
for i in range(1, height): # Rows
for j in range(width): # Columns
b = Entry(self.root, text="")
b.grid(row=i, column=j)
def settitle(self, text="Academy Management System"):
self.root.wm_title(text)
def control(self, location=None, name=None, year=None, date=None):
Button(self.root, text=" Location ", command=location, bg="#297ACC").grid(row=1, column=0)
Button(self.root, text=" Name ", command=name, bg="#297ACC").grid(row=3, column=0)
Button(self.root, text=" Year ", command=year, bg="#297ACC").grid(row=5, column=0)
Button(self.root, text=" Date ", command=date, bg="#297ACC").grid(row=7, column=0)
def setdefault(self):
for i in range(1, 10): # Rows
for j in range(1, 7): # Columns
b = Entry(self.root, text="")
b.grid(row=i, column=j)
self.height = 9
self.width = 6
self.root.wm_title("Academy Management System")
Label(self.root, text="Name").grid(row=0, column=1)
Label(self.root, text="Year").grid(row=0, column=2)
Label(self.root, text="Time checked").grid(row=0, column=3)
Label(self.root, text="Location").grid(row=0, column=4)
Label(self.root, text="Id").grid(row=0, column=5)
Label(self.root, text="Rfid").grid(row=0, column=6)
def getcolumns(self):
return self.width
def getrows(self):
return self.height
def setrow(self, array, rownum, types=Label, start=1):
for at in range(len(array)):
types(self.root, text=array[at]).grid(row=rownum, column=at+start)
def setcolumn(self, array, columnnum, types=Label, start=1):
for at in range(len(array)):
types(self.root, text=array[at]).grid(row=at+start, column=columnnum)
def clearrow(self, rownum):
for clear in range(1, self.width+1):
Entry(self.root, text="").grid(row=rownum, column=clear)
def clearcolumn(self, columnnum):
for clear in range(1, self.height+1):
Entry(self.root, text="").grid(row=clear, column=columnnum)
def cleargrid(self):
for c in range(1, self.width+1):
for r in range(1, self.height+1):
Entry(self.root, text="").grid(row=r, column=c)
def deleteentry(self, row, column):
Entry(self.root, text="").grid(row=row+1, column=column+1)
@staticmethod
def start():
mainloop()