Untitled
import tkinter as tk from tkinter import ttk, messagebox, filedialog, PhotoImage def send_sms(): recipients = numbers_list.get(0, tk.END) message = message_text.get("1.0", tk.END).strip() if not recipients: messagebox.showerror("Error", "Recipient list is empty.") return if not message: messagebox.showerror("Error", "Message cannot be empty.") return for recipient in recipients: print(f"Sending SMS to {recipient}: {message}") messagebox.showinfo("Success", "Messages sent successfully!") def load_contacts(): file_path = filedialog.askopenfilename(filetypes=[["Text Files", "*.txt"]]) if file_path: with open(file_path, "r") as file: for line in file: numbers_list.insert(tk.END, line.strip()) def save_template(): template = message_text.get("1.0", tk.END).strip() if not template: messagebox.showerror("Error", "Message cannot be empty.") return with open("templates.txt", "a") as file: file.write(template + "\n\n") messagebox.showinfo("Success", "Template saved successfully!") root = tk.Tk() root.title("PLMar SHS - SMS Announcement System") root.geometry("610x630") root.iconbitmap(r"e:\plmars.ico") canvas = tk.Canvas(root) scrollbar = tk.Scrollbar(root, orient="vertical", command=canvas.yview) scrollable_frame = tk.Frame(canvas) scrollable_frame.bind( "<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")) ) canvas.create_window((0, 0), window=scrollable_frame, anchor="n") canvas.configure(yscrollcommand=scrollbar.set) scrollbar.pack(side="right", fill="y") canvas.pack(side="left", fill="both", expand=True) header_frame = tk.Frame(scrollable_frame, bg="#4CAAD8", height=80) header_frame.pack(fill=tk.X, pady=10) try: logo = PhotoImage(file="e:\plmarsnobg.png") resized_logo = logo.subsample(3,3) logo_label = tk.Label(header_frame, image=resized_logo, bg="#4CAAD8") logo_label.image = resized_logo logo_label.pack(side=tk.LEFT, padx=10) except Exception as e: print("Error loading logo", e) header_label = tk.Label(header_frame, text="PAMANTASAN NG LUNGSOD NG MARIKINA\nSENIOR HIGH SCHOOL\nSMS ANNOUNCEMENT SYSTEM", bg="#4CAAD8", fg="white", font=("Arial", 14, "bold")) header_label.pack(padx=10, side=tk.LEFT) input_frame = tk.Frame(scrollable_frame, padx=10, pady=10) input_frame.pack(fill=tk.X, expand=True) recipient_label = tk.Label(input_frame, text="Enter Recipient Number:", font=("Arial", 10)) recipient_label.grid(row=0, column=0, sticky="e", padx=5, pady=5) recipient_entry = tk.Entry(input_frame, width=25) recipient_entry.grid(row=0, column=1, sticky="w", padx=5, pady=5) add_button = tk.Button(input_frame, text="Add", width=10, command=lambda: numbers_list.insert(tk.END, recipient_entry.get())) add_button.grid(row=0, column=2, sticky="w", padx=5, pady=5) load_button = tk.Button(input_frame, text="Load Contacts From File", width=20, command=load_contacts) load_button.grid(row=0, column=3, sticky="w", padx=5, pady=5) total_label = tk.Label(input_frame, text="Total Numbers:", font=("Arial", 10, "bold")) total_label.grid(row=1, column=0, sticky="w", pady=10) numbers_list = tk.Listbox(input_frame, width=50, height=10) numbers_list.grid(row=2, column=0, columnspan=4, pady=5, sticky="nsew") message_frame = tk.Frame(scrollable_frame, padx=10, pady=10) message_frame.pack(fill=tk.X, expand=True) message_label = tk.Label(message_frame, text="Message:", font=("Arial", 10)) message_label.pack(anchor="w") message_text = tk.Text(message_frame, height=8, width=50) message_text.pack(fill=tk.BOTH, pady=5) example_message = """Good morning, PLMarians! Please be informed that there will be changes to the regular class schedule today. The revised schedule is as follows: - Grade 11: 9:00 AM - 12:00 PM - Grade 12: 1:00 PM - 4:00 PM Thank you!""" message_text.insert(tk.END, example_message) options_frame = tk.Frame(scrollable_frame, padx=10, pady=10) options_frame.pack(fill=tk.X, expand=True) mobile_device_label = tk.Label(options_frame, text="Selected Mobile Device:", font=("Arial", 10)) mobile_device_label.grid(row=0, column=0, sticky="w", padx=5, pady=5) device_label = tk.Label(options_frame, text="SAMSUNG S20 Ultra", font=("Arial", 10, "bold")) device_label.grid(row=0, column=1, sticky="w", padx=5, pady=5) status_label = tk.Label(options_frame, text="Status: Disconnected", bg="purple", fg="white", font=("Arial", 10)) status_label.grid(row=1, column=0, columnspan=2, sticky="w", pady=5) one_time_radio = tk.Radiobutton(options_frame, text="One-Time Execution", value=1) one_time_radio.grid(row=2, column=0, sticky="w", pady=5) one_by_one_radio = tk.Radiobutton(options_frame, text="One-by-One Execution Mode", value=2) one_by_one_radio.grid(row=3, column=0, sticky="w") delay_checkbox = tk.Checkbutton(options_frame, text="Delayed Delivery:") delay_checkbox.grid(row=4, column=0, sticky="w") delay_frame = tk.Frame(options_frame) delay_frame.grid(row=4, column=1, sticky="w") delay_sms_spinbox = tk.Spinbox(delay_frame, from_=1, to=10, width=5) delay_sms_spinbox.pack(side=tk.LEFT) delay_sms_label = tk.Label(delay_frame, text="SMS") delay_sms_label.pack(side=tk.LEFT, padx=5) delay_time_spinbox = tk.Spinbox(delay_frame, from_=1, to=10, width=5) delay_time_spinbox.pack(side=tk.LEFT) delay_time_label = tk.Label(delay_frame, text="Sec.") delay_time_label.pack(side=tk.LEFT, padx=5) save_sent_checkbox = tk.Checkbutton(options_frame, text="Save Sent Messages") save_sent_checkbox.grid(row=5, column=0, sticky="w", pady=5) save_templates_checkbox = tk.Checkbutton(options_frame, text="Save sent message to Templates", command=save_template) save_templates_checkbox.grid(row=6, column=0, sticky="w") view_templates_button = tk.Button(options_frame, text="View Templates", width=15, command=lambda: messagebox.showinfo("Templates", "Templates saved to templates.txt")) view_templates_button.grid(row=6, column=1, sticky="w") button_frame = tk.Frame(scrollable_frame, padx=10, pady=10) button_frame.pack(fill=tk.X, expand=True) send_items_button = tk.Button(button_frame, text="SEND ITEMS", width=15, bg="green", fg="white", command=send_sms) send_items_button.pack(side=tk.LEFT, padx=5) send_button = tk.Button(button_frame, text="SEND", width=15, bg="blue", fg="white", command=send_sms) send_button.pack(side=tk.LEFT, padx=5) reset_button = tk.Button(button_frame, text="RESET", width=15, bg="red", fg="white", command=lambda: [numbers_list.delete(0, tk.END), message_text.delete("1.0", tk.END)]) reset_button.pack(side=tk.LEFT, padx=5) footer_frame = tk.Frame(scrollable_frame, padx=10, pady=10) footer_frame.pack(fill=tk.X, expand=True) about_button = tk.Button(footer_frame, text="ABOUT", width=10, command=lambda: messagebox.showinfo("About", "PLMar SHS SMS Announcement System\nVersion 1.0")) about_button.pack(side=tk.LEFT, padx=5) help_button = tk.Button(footer_frame, text="HELP", width=10, command=lambda: messagebox.showinfo("Help", "For assistance, contact support@plmar.edu.ph")) help_button.pack(side=tk.LEFT, padx=5) root.mainloop()
Leave a Comment