create an executable windows application that will have a spreadsheet that has the…
- User
create an executable windows application that will have a spreadsheet that has the following columns that can be sorted by (x): Task(alphabetically), Job(alphabetically), Due Date(by date), Date added(by date).
- Assistant
I'll create a simple Windows application with a sortable spreadsheet. Here's a Python script using PyQt5 that creates an executable spreadsheet application with the columns you requested:
import sys import datetime from PyQt5.QtWidgets import (QApplication, QMainWindow, QTableWidget, QTableWidgetItem, QVBoxLayout, QWidget, QPushButton, QHBoxLayout, QLineEdit, QLabel, QDateEdit, QHeaderView) from PyQt5.QtCore import Qt, QDate class TaskManager(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Task Manager") self.setGeometry(100, 100, 800, 600) # Main widget and layout self.central_widget = QWidget() self.setCentralWidget(self.central_widget) self.layout = QVBoxLayout(self.central_widget) # Input fields self.input_layout = QHBoxLayout() # Task input self.task_label = QLabel("Task:") self.task_input = QLineEdit() self.input_layout.addWidget(self.task_label) self.input_layout.addWidget(self.task_input) # Job input self.job_label = QLabel("Job:") self.job_input = QLineEdit() self.input_layout.addWidget(self.job_label) self.input_layout.addWidget(self.job_input) # Due date input self.due_date_label = QLabel("Due Date:") self.due_date_input = QDateEdit() self.due_date_input.setDate(QDate.currentDate()) self.due_date_input.setCalendarPopup(True) self.input_layout.addWidget(self.due_date_label) self.input_layout.addWidget(self.due_date_input) # Add button self.add_button = QPushButton("Add Task") self.add_button.clicked.connect(self.add_task) self.input_layout.addWidget(self.add_button) self.layout.addLayout(self.input_layout) # Table setup self.table = QTableWidget() self.table.setColumnCount(4) self.table.setHorizontalHeaderLabels(["Task", "Job", "Due Date", "Date Added"]) self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.table.horizontalHeader().sectionClicked.connect(self.sort_table) self.layout.addWidget(self.table) # Delete button self.delete_button = QPushButton("Delete Selected Task") self.delete_button.clicked.connect(self.delete_task) self.layout.addWidget(self.delete_button) # Initialize data self.tasks = [] def add_task(self): task = self.task_input.text() job = self.job_input.text() due_date = self.due_date_input.date().toString("yyyy-MM-dd") date_added = datetime.datetime.now().strftime("%Y-%m-%d") if task and job: self.tasks.append({ "task": task, "job": job, "due_date": due_date, "date_added": date_added }) self.update_table() # Clear inputs self.task_input.clear() self.job_input.clear() self.due_date_input.setDate(QDate.currentDate()) def update_table(self): self.table.setRowCount(len(self.tasks)) for row, task in enumerate(self.tasks): self.table.setItem(row, 0, QTableWidgetItem(task["task"])) self.table.setItem(row, 1, QTableWidgetItem(task["job"])) self.table.setItem(row, 2, QTableWidgetItem(task["due_date"])) self.table.setItem(row, 3, QTableWidgetItem(task["date_added"])) def delete_task(self): selected_rows = set() for item in self.table.selectedItems(): selected_rows.add(item.row()) # Remove tasks in reverse order to avoid index issues for row in sorted(selected_rows, reverse=True): if 0 <= row < len(self.tasks): self.tasks.pop(row) self.update_table() def sort_table(self, column): if column == 0: # Task (alphabetically) self.tasks.sort(key=lambda x: x["task"].lower()) elif column == 1: # Job (alphabetically) self.tasks.sort(key=lambda x: x["job"].lower()) elif column == 2: # Due Date (by date) self.tasks.sort(key=lambda x: x["due_date"]) elif column == 3: # Date Added (by date) self.tasks.sort(key=lambda x: x["date_added"]) self.update_table() if __name__ == "__main__": app = QApplication(sys.argv) window = TaskManager() window.show() sys.exit(app.exec_())To make this into an executable Windows application, you'll need to:
-
Install the required packages:
- PyQt5
- PyInstaller
-
Save the code above to a file named
task_manager.py -
Run PyInstaller to create the executable:
pyinstaller --onefile --windowed task_manager.py
The executable will be created in the
distfolder and will have all the features you requested:- A spreadsheet with columns for Task, Job, Due Date, and Date Added
- Ability to sort by clicking column headers:
- Task (alphabetically)
- Job (alphabetically)
- Due Date (by date)
- Date Added (by date)
- Add and delete functionality
Would you like me to explain or break down the code?
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.