Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
File Based To Do
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jacob Christy
File Based To Do
Commits
a87a2f83
Commit
a87a2f83
authored
3 years ago
by
Jacob
Browse files
Options
Downloads
Patches
Plain Diff
Save/remove finished, reads/writes from file now
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ToDo.py
+121
-0
121 additions, 0 deletions
ToDo.py
with
121 additions
and
0 deletions
ToDo.py
0 → 100644
+
121
−
0
View file @
a87a2f83
from
tkinter
import
*
import
tkinter
as
tk
class
ToDoItem
:
def
__init__
(
self
,
name
,
description
):
self
.
name
=
name
self
.
description
=
description
class
ToDoApp
:
def
__init__
(
self
,
root
):
root
.
title
(
"
To Do App
"
)
# root.geometry("500x400")
# root.maxsize(800, 800)
frame
=
Frame
(
root
,
borderwidth
=
2
,
relief
=
"
sunken
"
)
frame
.
grid
(
column
=
1
,
row
=
1
,
sticky
=
(
N
,
E
,
S
,
W
))
root
.
columnconfigure
(
1
,
weight
=
1
)
root
.
rowconfigure
(
1
,
weight
=
1
)
self
.
to_do_items
=
[]
# Construct to do list from file
file1
=
open
(
"
ToDoItems.txt
"
,
"
r
"
)
while
True
:
line
=
file1
.
readline
()
if
not
line
:
break
line_list
=
line
.
split
(
"
,
"
)
item
=
ToDoItem
(
line_list
[
0
],
line_list
[
1
])
self
.
to_do_items
.
append
(
item
)
file1
.
close
()
# To do list
list_label
=
Label
(
frame
,
text
=
"
To Do
"
)
list_label
.
grid
(
column
=
1
,
row
=
1
,
sticky
=
(
S
,
W
))
self
.
to_do_names
=
StringVar
(
value
=
list
(
map
(
lambda
x
:
x
.
name
,
self
.
to_do_items
)))
items_list
=
Listbox
(
frame
,
listvariable
=
self
.
to_do_names
)
items_list
.
bind
(
"
<<ListboxSelect>>
"
,
lambda
s
:
self
.
select_item
(
items_list
.
curselection
()))
items_list
.
grid
(
column
=
1
,
row
=
2
,
sticky
=
(
E
,
W
),
rowspan
=
5
)
self
.
selected_descrip
=
StringVar
()
selected_descrip_label
=
Label
(
frame
,
textvariable
=
self
.
selected_descrip
,
wraplength
=
200
)
selected_descrip_label
.
grid
(
column
=
1
,
row
=
7
,
sticky
=
(
E
,
W
))
# New Items
new_item_label
=
Label
(
frame
,
text
=
"
New Item
"
)
new_item_label
.
grid
(
column
=
2
,
row
=
1
,
sticky
=
(
S
,
W
))
name_label
=
Label
(
frame
,
text
=
"
Item name
"
)
name_label
.
grid
(
column
=
2
,
row
=
2
,
sticky
=
(
S
,
W
))
self
.
name
=
StringVar
()
name_entry
=
Entry
(
frame
,
textvariable
=
self
.
name
)
name_entry
.
grid
(
column
=
2
,
row
=
3
,
sticky
=
(
N
,
E
,
W
))
descrip_label
=
Label
(
frame
,
text
=
"
Item description
"
)
descrip_label
.
grid
(
column
=
2
,
row
=
4
,
sticky
=
(
S
,
W
))
self
.
descrip
=
StringVar
()
description_entry
=
Entry
(
frame
,
textvariable
=
self
.
descrip
)
description_entry
.
grid
(
column
=
2
,
row
=
5
,
sticky
=
(
N
,
E
,
W
))
save_button
=
Button
(
frame
,
text
=
"
Save
"
,
command
=
self
.
save_item
)
save_button
.
configure
(
width
=
8
,
height
=
1
,
font
=
(
"
Courier
"
,
10
))
save_button
.
grid
(
column
=
2
,
row
=
6
,
sticky
=
(
E
,
W
))
# Remove items
remove_button
=
Button
(
frame
,
text
=
"
Finish
"
,
command
=
lambda
:
self
.
remove_item
(
items_list
.
curselection
()))
remove_button
.
configure
(
width
=
8
,
height
=
1
,
font
=
(
"
Courier
"
,
10
))
remove_button
.
grid
(
column
=
2
,
row
=
7
,
sticky
=
(
E
,
W
))
# Padding
for
child
in
frame
.
winfo_children
():
child
.
grid_configure
(
padx
=
10
,
pady
=
5
)
def
save_item
(
self
):
self
.
to_do_items
.
append
(
ToDoItem
(
self
.
name
.
get
(),
self
.
descrip
.
get
()))
self
.
to_do_names
.
set
(
list
(
map
(
lambda
x
:
x
.
name
,
self
.
to_do_items
)))
self
.
name
.
set
(
""
)
self
.
descrip
.
set
(
""
)
self
.
update_file
()
def
remove_item
(
self
,
index
):
if
(
index
!=
()):
del
self
.
to_do_items
[
index
[
0
]]
self
.
to_do_names
.
set
(
list
(
map
(
lambda
x
:
x
.
name
,
self
.
to_do_items
)))
self
.
update_file
()
def
select_item
(
self
,
index
):
if
(
index
!=
()):
selected_item
=
self
.
to_do_items
[
index
[
0
]]
self
.
selected_descrip
.
set
(
selected_item
.
description
)
def
update_file
(
self
):
file1
=
open
(
"
ToDoItems.txt
"
,
"
w
"
)
for
item
in
self
.
to_do_items
:
line
=
item
.
name
+
"
,
"
+
item
.
description
+
"
\n
"
file1
.
write
(
line
)
file1
.
close
()
root
=
Tk
()
ToDoApp
(
root
)
root
.
mainloop
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment