A nice desktop application project!
To create an executable Windows application with a spreadsheet-like interface, I'll guide you through a solution using:
- Python as the programming language
- Tkinter for the GUI framework (built-in Python library)
- ttk (Tkinter's themed widget library) for the table/spreadsheet component
- pandas for data manipulation and sorting
Here's a step-by-step tutorial:
Prerequisites:
- Install Python (if not already installed) from the official website: https://www.python.org/downloads/
- Install the required libraries by running the following command in your terminal/command prompt:
pip install pandas
The Code:
Create a new file named task_manager.py and paste the following code:
import tkinter as tk
from tkinter import ttk
import pandas as pd
from datetime import datetime
# Sample data (you can replace this with your own data source)
data = {
"Task": ["Task A", "Task C", "Task B", "Task D"],
"Job": ["Job 1", "Job 3", "Job 2", "Job 1"],
"Due Date": ["2024-03-15", "2024-02-20", "2024-04-01", "2024-01-15"],
"Date Added": ["2024-01-01", "2024-01-05", "2024-01-03", "2024-01-02"]
}
class TaskManager:
def __init__(self, root):
self.root = root
self.root.title("Task Manager")
self.root.geometry("800x600")
# Create a pandas DataFrame from the sample data
self.df = pd.DataFrame(data)
# Convert date columns to datetime format
self.df["Due Date"] = pd.to_datetime(self.df["Due Date"])
self.df["Date Added"] = pd.to_datetime(self.df["Date Added"])
# Create the GUI components
self.create_widgets()
def create_widgets(self):
# Create a frame to hold the table
frame = tk.Frame(self.root)
frame.pack(fill="both", expand=True)
# Create the table (ttk.Treeview)
self.table = ttk.Treeview(frame)
# Define the columns
self.table["columns"] = ("Task", "Job", "Due Date", "Date Added")
# Format the columns
self.table.column("#0", width=0, stretch="no") # hide the first column
self.table.column("Task", anchor="w", width=200)
self.table.column("Job", anchor="w", width=150)
self.table.column("Due Date", anchor="center", width=120)
self.table.column("Date Added", anchor="center", width=120)
# Create headings with sorting buttons
self.table.heading("#0", text="", anchor="w")
self.table.heading("Task", text="Task", anchor="w", command=lambda: self.sort_table("Task", "alphabetical"))
self.table.heading("Job", text="Job", anchor="w", command=lambda: self.sort_table("Job", "alphabetical"))
self.table.heading("Due Date", text="Due Date", anchor="center", command=lambda: self.sort_table("Due Date", "date"))
self.table.heading("Date Added", text="Date Added", anchor="center", command=lambda: self.sort_table("Date Added", "date"))
# Add data to the table
self.update_table()
# Pack the table
self.table.pack(fill="both", expand=True)
def update_table(self):
# Clear the table
for row in self.table.get_children():
self.table.delete(row)
# Insert data from the DataFrame
for index, row in self.df.iterrows():
self.table.insert("", "end", values=(
row["Task"],
row["Job"],
row["Due Date"].strftime("%Y-%m-%d"),
row["Date Added"].strftime("%Y-%m-%d")
))
def sort_table(self, column, sort_type):
# Sort the DataFrame based on the selected column and type
if sort_type == "alphabetical":
self.df = self.df.sort_values(by=column, ascending=True)
elif sort_type == "date":
self.df = self.df.sort_values(by=column, ascending=True)
# Update the table with the sorted data
self.update_table()
if __name__ == "__main__":
root = tk.Tk()
app = TaskManager(root)
root.mainloop()
How it works:
- The
TaskManager class initializes the GUI application, sets up the table structure, and populates it with sample data from the data dictionary.
- The
create_widgets method creates the table (a ttk.Treeview widget) and defines its columns. Each column heading is a button that triggers the sort_table method when clicked.
- The
update_table method clears the table and inserts data from the pandas DataFrame.
- The
sort_table method sorts the DataFrame based on the selected column and type (alphabetical or date). It then updates the table with the sorted data.
Run the application:
- Save the
task_manager.py file.
- Open a terminal/command prompt and navigate to the directory where you saved the file.
- Run the application using Python:
python task_manager.py
This will launch the GUI application. You should see a window with a table containing the sample data.
Interact with the application:
- Click on the column headings to sort the data:
- Task and Job columns sort alphabetically.
- Due Date and Date Added columns sort by date (oldest first).
- The table updates dynamically as you sort the data.
Create an executable (.exe) file:
To distribute your application, you'll need to create a standalone executable file. We'll use PyInstaller for this:
- Install PyInstaller:
pip install pyinstaller
- Navigate to the directory containing your
task_manager.py file.
- Run the following command:
pyinstaller --onefile --windowed task_manager.py
This will create a dist directory containing the executable file (task_manager.exe).
That's it!
Now you have a Windows executable application with a spreadsheet-like interface, featuring sortable columns for Task, Job, Due Date, and Date Added.
Distribute the task_manager.exe file, and users can run it without needing Python or any dependencies installed.
Happy coding!