Skip to content

Commit 800eb9d

Browse files
Merge pull request #7 from robinrcoe/master
added todo
2 parents 17292a4 + e2cffe8 commit 800eb9d

File tree

1 file changed

+183
-0
lines changed
  • Mini Project/ToDo-gui-python

1 file changed

+183
-0
lines changed

Mini Project/ToDo-gui-python/todo.py

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# import all functions from the tkinter
2+
from tkinter import *
3+
4+
# import messagebox class from tkinter
5+
from tkinter import messagebox
6+
7+
# global list is declare for storing all the task
8+
tasks_list = []
9+
10+
# global variable is declare for couting the task
11+
counter = 1
12+
13+
# Function for checking input error when
14+
# empty input is given in task field
15+
def inputError() :
16+
17+
# check for enter task field is empty or not
18+
if enterTaskField.get() == "" :
19+
20+
# show the error message
21+
messagebox.showerror("Input Error")
22+
23+
return 0
24+
25+
return 1
26+
27+
# Function for clearing the contents
28+
# of task number text field
29+
def clear_taskNumberField() :
30+
31+
# clear the content of task number text field
32+
taskNumberField.delete(0.0, END)
33+
34+
# Function for clearing the contents
35+
# of task entry field
36+
def clear_taskField() :
37+
38+
# clear the content of task field entry box
39+
enterTaskField.delete(0, END)
40+
41+
# Function for inserting the contents
42+
# from the task entry field to the text area
43+
def insertTask():
44+
45+
global counter
46+
47+
# check for error
48+
value = inputError()
49+
50+
# if error occur then return
51+
if value == 0 :
52+
return
53+
54+
# get the task string concatenating
55+
# with new line character
56+
content = enterTaskField.get() + "\n"
57+
58+
# store task in the list
59+
tasks_list.append(content)
60+
61+
# insert content of task entry field to the text area
62+
# add task one by one in below one by one
63+
TextArea.insert('end -1 chars', "[ " + str(counter) + " ] " + content)
64+
65+
# incremented
66+
counter += 1
67+
68+
# function calling for deleting the content of task field
69+
clear_taskField()
70+
71+
# function for deleting the specified task
72+
def delete() :
73+
74+
global counter
75+
76+
# handling the empty task error
77+
if len(tasks_list) == 0 :
78+
messagebox.showerror("No task")
79+
return
80+
81+
# get the task number, which is required to delete
82+
number = taskNumberField.get(1.0, END)
83+
84+
# checking for input error when
85+
# empty input in task number field
86+
if number == "\n" :
87+
messagebox.showerror("input error")
88+
return
89+
90+
else :
91+
task_no = int(number)
92+
93+
# function calling for deleting the
94+
# content of task number field
95+
clear_taskNumberField()
96+
97+
# deleted specified task from the list
98+
tasks_list.pop(task_no - 1)
99+
100+
# decremented
101+
counter -= 1
102+
103+
# whole content of text area widget is deleted
104+
TextArea.delete(1.0, END)
105+
106+
# rewriting the task after deleting one task at a time
107+
for i in range(len(tasks_list)) :
108+
TextArea.insert('end -1 chars', "[ " + str(i + 1) + " ] " + tasks_list[i])
109+
110+
111+
# Driver code
112+
if __name__ == "__main__" :
113+
114+
# create a GUI window
115+
gui = Tk()
116+
117+
# set the background colour of GUI window
118+
gui.configure(background = "#94d3f7")
119+
120+
# set the title of GUI window
121+
gui.title("ToDo App")
122+
123+
# set the configuration of GUI window
124+
gui.geometry("250x300")
125+
126+
# create a label : Enter Your Task
127+
enterTask = Label(gui, text = "Enter Your Task", background="#94d3f7")
128+
129+
# create a text entry box
130+
# for typing the task
131+
enterTaskField = Entry(gui, background="#e8e9ed")
132+
133+
# create a Submit Button and place into the root window
134+
# when user press the button, the command or
135+
# function affiliated to that button is executed
136+
Submit = Button(gui, text = "Submit", fg = "Black", bg = "#fafcfc", command = insertTask)
137+
138+
# create a text area for the root
139+
# with lunida 13 font
140+
# text area is for writing the content
141+
TextArea = Text(gui, height = 5, width = 25, font = "lucida 13", background="#e8e9ed")
142+
143+
# create a label : Delete Task Number
144+
taskNumber = Label(gui, text="Delete Task Number", bg = "#94d3f7")
145+
146+
taskNumberField = Text(gui, height = 1, width = 2, font = "lucida 13", background="#e8e9ed")
147+
148+
# create a Delete Button and place into the root window
149+
# when user press the button, the command or
150+
# function affiliated to that button is executed .
151+
delete = Button(gui, text = "Delete", fg = "Black", bg = "#fafcfc", command = delete)
152+
153+
# create a Exit Button and place into the root window
154+
# when user press the button, the command or
155+
# function affiliated to that button is executed .
156+
Exit = Button(gui, text = "Exit", fg = "Black", bg = "#f25f49", command = exit)
157+
158+
# grid method is used for placing
159+
# the widgets at respective positions
160+
# in table like structure.
161+
enterTask.grid(row = 0, column = 2)
162+
163+
# ipadx attributed set the entry box horizontal size
164+
enterTaskField.grid(row = 1, column = 2, ipadx = 50)
165+
166+
Submit.grid(row = 3, column = 2)
167+
168+
# padx attributed provide x-axis margin
169+
# from the root window to the widget.
170+
TextArea.grid(row = 5, column = 2, padx = 10, sticky = W)
171+
172+
taskNumber.grid(row = 6, column = 2, pady = 5)
173+
174+
taskNumberField.grid(row = 7, column = 2)
175+
176+
# pady attributed provide y-axis
177+
# margin from the widget.
178+
delete.grid(row = 8, column = 2, pady = 5)
179+
180+
Exit.grid(row = 9, column = 2)
181+
182+
# start the GUI
183+
gui.mainloop()

0 commit comments

Comments
 (0)