Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # todolist.py
- import Tkinter as tk
- class Todo(tk.Frame):
- def __init__(self,parent,tasks=None):
- tk.Frame.__init__(self,parent)
- if not tasks:
- self.tasks=[]
- else:
- self.tasks=tasks
- parent.title("To-Do App v1")
- parent.geometry("300x400")
- todol=tk.Label(self,text="-- Add Items Here --",bg="lightgrey",fg="black",pady=10)
- self.tasks.append(todol)
- for task in self.tasks:
- task.pack(side=tk.TOP,fill=tk.X)
- self.task_creat=tk.Text(self,height=3,bg="white",fg="black")
- self.task_creat.pack(side=tk.BOTTOM,fill=tk.X)
- self.task_creat.focus_set()
- self.task_creat.bind("<Return>",self.add_task)
- self.colour_schemes=[{"bg":"lightgrey","fg":"black"},{"bg":"grey","fg":"white"}]
- def add_task(self,event=None):
- task_text=self.task_creat.get(1.0,tk.END).strip()
- if len(task_text)>0:
- new_task = tk.Label(self,text=task_text,pady=10)
- _,task_style_choice=divmod(len(self.tasks),2)
- my_scheme_choice = self.colour_schemes[task_style_choice]
- new_task.configure(bg=my_scheme_choice["bg"])
- new_task.configure(fg=my_scheme_choice["fg"])
- new_task.pack(side=tk.TOP,fill=tk.X)
- self.tasks.append(new_task)
- self.task_creat.delete(1.0,tk.END)
- if __name__=="__main__":
- todo=tk.Tk()
- app=Todo(todo)
- app.pack()
- todo.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement