Advertisement
here2share

# todolist.py

May 22nd, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. # todolist.py
  2.  
  3. import Tkinter as tk
  4. class Todo(tk.Frame):
  5.     def __init__(self,parent,tasks=None):
  6.         tk.Frame.__init__(self,parent)
  7.         if not tasks:
  8.             self.tasks=[]
  9.         else:
  10.             self.tasks=tasks
  11.         parent.title("To-Do App v1")
  12.         parent.geometry("300x400")
  13.         todol=tk.Label(self,text="-- Add Items Here --",bg="lightgrey",fg="black",pady=10)
  14.         self.tasks.append(todol)
  15.         for task in self.tasks:
  16.             task.pack(side=tk.TOP,fill=tk.X)
  17.         self.task_creat=tk.Text(self,height=3,bg="white",fg="black")
  18.         self.task_creat.pack(side=tk.BOTTOM,fill=tk.X)
  19.         self.task_creat.focus_set()
  20.         self.task_creat.bind("<Return>",self.add_task)
  21.         self.colour_schemes=[{"bg":"lightgrey","fg":"black"},{"bg":"grey","fg":"white"}]
  22.     def add_task(self,event=None):
  23.         task_text=self.task_creat.get(1.0,tk.END).strip()
  24.         if len(task_text)>0:
  25.             new_task = tk.Label(self,text=task_text,pady=10)
  26.             _,task_style_choice=divmod(len(self.tasks),2)
  27.             my_scheme_choice = self.colour_schemes[task_style_choice]
  28.             new_task.configure(bg=my_scheme_choice["bg"])
  29.             new_task.configure(fg=my_scheme_choice["fg"])
  30.             new_task.pack(side=tk.TOP,fill=tk.X)
  31.             self.tasks.append(new_task)
  32.         self.task_creat.delete(1.0,tk.END)
  33.  
  34. if __name__=="__main__":
  35.     todo=tk.Tk()
  36.     app=Todo(todo)
  37.     app.pack()
  38.     todo.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement