-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmix_try1.py
165 lines (138 loc) · 5.57 KB
/
mix_try1.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
from tkinter import *
from tkinter import font
import csv
import codecs
def whichSelected () :
#print("At %s of %d" % (select.curselection(), len(data)))
return int(select.curselection()[0])
def addEntry () :
na,rm,dt,ven = [nameVar.get(), rmtypeVar.get(), dateVar.get(), venueVar.get()]
for i in data:
#print(i)
if dt in i and rm in i:
messageBox.delete('1.0',END)
messageBox.insert(END,"This event can not be registered. Either because of slot and venue might be clashing")
messageBox.tag_add("start", "1.0", "1.100")
messageBox.tag_config("start", background="white", foreground="red")
break
else:
data.append ([nameVar.get(), rmtypeVar.get(), dateVar.get(), venueVar.get()])
messageBox.delete('1.0',END)
messageBox.insert(END,"Your event "+nameVar.get()+" was successfully registered")
messageBox.tag_add("start", "1.0", "1.100")
messageBox.tag_config("start", background="white", foreground="green")
setSelect ()
def updateEntry() :
try:
messageBox.delete('1.0',END)
messageBox.insert(END,"Your event "+nameVar.get()+" was updated")
messageBox.tag_add("start", "1.0", "1.100")
messageBox.tag_config("start", background="white", foreground="grey")
data[whichSelected()] = [nameVar.get(), rmtypeVar.get(), dateVar.get(), venueVar.get()]
except: IndexError
setSelect ()
def deleteEntry() :
try:
messageBox.delete('1.0',END)
messageBox.insert(END,"Your event "+data[whichSelected()][0]+" at "+data[whichSelected()][3]+" was successfully deleted")
messageBox.tag_add("start", "1.0", "1.100")
messageBox.tag_config("start", background="white", foreground="blue")
del data[whichSelected()]
except: IndexError
setSelect ()
def loadEntry () :
name, rmtype, date, venue = data[whichSelected()]
nameVar.set(name)
rmtypeVar.set(rmtype)
dateVar.set(date)
venueVar.set(venue)
def makeWindow () :
global nameVar, rmtypeVar, dateVar, venueVar, select, data, messageBox
data=[]
win = Tk()
my_font = font.Font(family="Monaco", size=12)
select = Listbox(win,width=100,font = my_font)
with open("eventListNew.csv",encoding="utf-8-sig") as csvFile:
reader = csv.reader(csvFile)
for row in reader:
data.append([row[0],row[1],row[2],row[3]])
csvFile.close()
for i in data:
select.insert(END,"{:<20s}{:<20s}{:<20s}{:<20s}".format(i[0],i[1],i[2],i[3]))
buttonFrame = Frame()
but1 = Button(buttonFrame,text=" Name ",command = lambda: sortAccord(0))
but2 = Button(buttonFrame,text=" Room Type ",command = lambda: sortAccord(1))
but3 = Button(buttonFrame,text=" Date ",command = lambda: sortAccord(2))
but4 = Button(buttonFrame,text=" Venue ",command = lambda: sortAccord(3))
but1.pack(side=LEFT,padx=10,pady=10)
but2.pack(side=LEFT,padx=15,pady=10)
but3.pack(side=LEFT,padx=35,pady=10)
but4.pack(side=LEFT,padx=20,pady=10)
buttonFrame.pack(side=TOP)
select.pack()
frame1 = Frame(win)
frame1.pack()
Label(frame1, text="Event Name").grid(row=0, column=0, sticky=W)
nameVar = StringVar()
name = Entry(frame1, textvariable=nameVar)
name.grid(row=0, column=1, sticky=W)
Label(frame1, text="Room Type").grid(row=1, column=0, sticky=W)
rmtypeVar= StringVar()
rmtype= Entry(frame1, textvariable=rmtypeVar)
rmtype.grid(row=1, column=1, sticky=W)
Label(frame1, text="Date").grid(row=2, column=0, sticky=W)
dateVar = StringVar()
date = Entry(frame1, textvariable=dateVar)
date.grid(row=2, column=1, sticky=W)
Label(frame1, text="Venue").grid(row=3, column=0, sticky=W)
venueVar = StringVar()
venue = Entry(frame1, textvariable=venueVar)
venue.grid(row=3, column=1, sticky=W)
frame2 = Frame(win) # Row of buttons
frame2.pack()
b1 = Button(frame2,text=" Add ",command=addEntry)
b2 = Button(frame2,text="Update",command=updateEntry)
b3 = Button(frame2,text="Delete",command=deleteEntry)
b4 = Button(frame2,text=" Load ",command=loadEntry)
b1.pack(side=LEFT,padx=10,pady=20); b2.pack(side=LEFT,padx=10,pady=20)
b3.pack(side=LEFT,padx=10,pady=20); b4.pack(side=LEFT,padx=10,pady=20)
#frame3 = Frame(win) # select of names
#frame3.pack()
#scroll = Scrollbar(frame3, orient=VERTICAL)
#select = Listbox(frame3, yscrollcommand=scroll.set, height=6)
#scroll.config (command=select.yview)
#scroll.pack(side=RIGHT, fill=Y)
#select.pack(side=LEFT, fill=BOTH, expand=1)
frame4 = Frame(win) #message box label
frame4.pack()
messageLabel = Label(frame4,text="Message Box")
messageLabel.pack(padx=10,pady=10)
messageBox = Text(frame4,height=3,width=50)
#messageBox.insert(END,"j")
messageBox.pack(side = LEFT,padx=10,pady=10)
return win
def sortAccord(copy):
global l2
l = [i.split() for i in select.get(0,END)]
select.delete(0,END)
l2 = {}
for i in l:
x = i[copy].lower()
if x not in l2.keys():
l2[x] = [i]
else:
l2[x] += [i]
l4 = list(sorted(l2.keys()))
for i in l4:
for j in range(len(l2[i])):
select.insert(END,"{:<20s}{:<20s}{:<20s}{:<20s}".format(l2[i][j][0],l2[i][j][1],l2[i][j][2],l2[i][j][3]))
def setSelect() :
data.sort()
select.delete(0,END)
for i in data:
select.insert(END,"{:<20s}{:<20s}{:<20s}{:<20s}".format(i[0],i[1],i[2],i[3]))
#win.geometry("400x200")
win = makeWindow()
win.title("Eveniser")
setSelect ()
win.mainloop()