Advertisement
MGakowski

Planner

Mar 28th, 2023
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.08 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3.  
  4. class PlannerApp:
  5.     def __init__(self, master):
  6.         self.master = master
  7.         self.master.title("Weekly Planner")
  8.         self.master.geometry("800x600")
  9.  
  10.         self.days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
  11.  
  12.         # Create a frame to hold the planner grid
  13.         self.planner_frame = ttk.Frame(self.master)
  14.         self.planner_frame.pack(padx=20, pady=20)
  15.  
  16.         # Create a grid of labels for each day of the week
  17.         for i, day in enumerate(self.days):
  18.             day_label = ttk.Label(self.planner_frame, text=day)
  19.             day_label.grid(row=0, column=i+1, padx=10, pady=10)
  20.  
  21.         # Create a list of task labels
  22.         self.tasks = []
  23.         for i in range(10):
  24.             task = f"Task {i+1}"
  25.             self.tasks.append(task)
  26.  
  27.         # Create a list of labels for each task
  28.         self.task_labels = []
  29.         for i, task in enumerate(self.tasks):
  30.             task_label = ttk.Label(self.planner_frame, text=task, width=20)
  31.             task_label.grid(row=i+1, column=0, padx=10, pady=10)
  32.             self.task_labels.append(task_label)
  33.  
  34.         # Create a list of entry boxes for each day and task
  35.         self.entries = []
  36.         for i in range(len(self.tasks)):
  37.             entries_row = []
  38.             for j in range(len(self.days)):
  39.                 entry = ttk.Entry(self.planner_frame, width=20)
  40.                 entry.grid(row=i+1, column=j+1, padx=10, pady=10)
  41.                 entries_row.append(entry)
  42.             self.entries.append(entries_row)
  43.  
  44.         # Allow tasks to be dragged and dropped onto different days
  45.         for task_label in self.task_labels:
  46.             task_label.bind("<ButtonPress-1>", self.on_start)
  47.             task_label.bind("<B1-Motion>", self.on_drag)
  48.             task_label.bind("<ButtonRelease-1>", self.on_drop)
  49.  
  50.     def on_start(self, event):
  51.         # Record the task label that was clicked on
  52.         widget = event.widget
  53.         self.current_task = self.task_labels.index(widget)
  54.         self.drag_start = (event.x_root, event.y_root)
  55.  
  56.     def on_drag(self, event):
  57.         # Calculate the x and y displacement of the task label
  58.         x_displacement = event.x_root - self.drag_start[0]
  59.         y_displacement = event.y_root - self.drag_start[1]
  60.  
  61.         # Move the task label by the displacement
  62.         widget = event.widget
  63.         widget.place(x=widget.winfo_x()+x_displacement, y=widget.winfo_y()+y_displacement)
  64.  
  65.     def on_drop(self, event):
  66.         # Record the day label that the task label was dropped onto
  67.         widget = event.widget
  68.         day = self.days.index(widget.cget("text")) + 1
  69.  
  70.         # Update the corresponding entry box with the task name
  71.         self.entries[self.current_task][day-1].delete(0, tk.END)
  72.         self.entries[self.current_task][day-1].insert(0, self.tasks[self.current_task])
  73.  
  74.         # Reset the position of the task label
  75.         widget.place(x=0, y=0)
  76.  
  77. if __name__ == "__main__":
  78.     root = tk.Tk()
  79.     app = PlannerApp(root)
  80.     root.mainloop()
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement