forked from prathimacode-hub/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecklist_app.py
105 lines (76 loc) · 2.81 KB
/
checklist_app.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
from tkinter import *
from tkinter import messagebox
#Define the root window
root=Tk()
root.title("My Checklist App")
root.geometry("400x400")
root.resizable(0,0)
#setting up app theme - font and colours
myFont=("Times New Roman",12)
rootColour = "#3b5998"
buttonColour = "#f7f7f7"
#changing root bg
root.config(bg=rootColour)
#FUNCTIONS
#ADD ITEM FUNCTION
def addItem():
if listEntry.get() == "":
messagebox.showinfo("Illegal Entry","Cannot Enter Blank Items")
else:
listBox.insert(END,listEntry.get())
listEntry.delete(0,END)
#REMOVE ITEM FUNCTION
def removeItem():
listBox.delete(ANCHOR)
#CLEAR LIST FUNCTION
def clearList():
listBox.delete(0,END)
#SAVE LIST FUNCTION
def saveList():
with open('checklist.txt','w') as f:
toSaveList = listBox.get(0,END)
#print(toSaveList)
for element in toSaveList:
if element.endswith("\n"):
f.write(element)
else:
f.write(element+"\n")
#READING FROM FILE WHEN ALL REOPENS
def openList():
try:
with open('checklist.txt','r') as f:
for line in f:
listBox.insert(END,line)
except:
return
#defining the layout of the app
#FRAMES LAYOUT
inputFrame = Frame(root,bg=rootColour)
outputFrame = Frame(root,bg=rootColour)
buttonFrame = Frame(root,bg=rootColour)
inputFrame.pack()
outputFrame.pack()
buttonFrame.pack()
#LAYOUT OF INPUT FRAME ELEMENTS
listEntry = Entry(inputFrame,width=35,borderwidth=3,font=myFont)
listAddButton = Button(inputFrame,text="Add Item",borderwidth=2,font=myFont,bg=buttonColour,command=addItem)
listEntry.grid(row=0,column=0,padx=5,pady=5)
listAddButton.grid(row=0,column=1,padx=5,pady=5,ipadx=5)
#LAYOUT OF OUTPUT FRAME
#Add scrollbar
scrollBar=Scrollbar(outputFrame)
listBox = Listbox(outputFrame,height=15,width=45,borderwidth=3,font=myFont,yscrollcommand=scrollBar.set)
scrollBar.config(command=listBox.yview )
listBox.grid(row=0,column=0)
scrollBar.grid(row=0,column=1,sticky="NS")
#LAYOUT OF BUTTON FRAME
listRemoveButton = Button(buttonFrame,text="Remove Item",borderwidth=2,font=myFont,bg=buttonColour,command=removeItem)
listClearButton = Button(buttonFrame,text="Clear List",borderwidth=2,font=myFont,bg=buttonColour,command=clearList)
saveButton = Button(buttonFrame,text="Save",borderwidth=2,font=myFont,bg=buttonColour,command=saveList)
quitButton = Button(buttonFrame,text="Quit",command=root.destroy,borderwidth=2,font=myFont,bg=buttonColour)
listRemoveButton.grid(row=0,column=0,padx=2,pady=10)
listClearButton.grid(row=0,column=1,padx=2,pady=10,ipadx=10)
saveButton.grid(row=0,column=2,padx=2,pady=10,ipadx=15)
quitButton.grid(row=0,column=30,padx=2,pady=10,ipadx=15)
openList()
root.mainloop()