Im trying to run my program as an exe file but also in the terminal and it gives me an error code. I can run the program without any problems in Visual Studio Code terminal.
import tkinter as tk
from tkinter import simpledialog, messagebox, Listbox, END
def savefile(savedlist, tasks):
with open(savedlist, 'w') as file:
for task in tasks:
file.write(task + 'n')
def load_file(filename):
tasks = []
try:
with open(filename, 'r') as file:
tasks = file.readlines()
tasks = [task.strip() for task in tasks]
except FileNotFoundError:
print("File not found, starting with empty list.")
return tasks
def add_task(tasks, listbox):
task = simpledialog.askstring("Add task", "Enter the new task:")
if task:
tasks.append(task)
listbox.insert(END, task)
savefile("savedlist.txt", tasks)
def view_tasks(tasks, listbox):
listbox.delete(0, END) # Clear the listbox
for task in tasks:
listbox.insert(END, task) # Insert all tasks again
def task_completed(tasks, listbox):
try:
index = listbox.curselection()[0]
task = tasks.pop(index)
listbox.delete(index)
print(f"Task {task} has been completed.")
savefile("savedlist.txt", tasks)
except IndexError:
messagebox.showinfo("Error", "Please select a task to mark as completed.")
def remove_task(tasks, listbox):
try:
index = listbox.curselection()[0]
task = tasks.pop(index)
listbox.delete(index)
print(f"Task {task} has been removed.")
savefile("savedlist.txt", tasks)
except IndexError:
messagebox.showinfo("Error", "Please select a task to remove.")
def main_menu():
root = tk.Tk()
root.title("Productive Assistant")
filename = "savedlist.txt"
tasks = load_file(filename)
listbox = Listbox(root, selectmode=tk.SINGLE)
listbox.pack(fill=tk.BOTH, expand=True)
add_button = tk.Button(root, text="Add Task", command=lambda: add_task(tasks, listbox))
add_button.pack(side=tk.LEFT, fill=tk.X, expand=True)
complete_button = tk.Button(root, text="Mark as Completed", command=lambda: task_completed(tasks, listbox))
complete_button.pack(side=tk.LEFT, fill=tk.X, expand=True)
remove_button = tk.Button(root, text="Remove Task", command=lambda: remove_task(tasks, listbox))
remove_button.pack(side=tk.LEFT, fill=tk.X, expand=True)
view_button = tk.Button(root, text="View Tasks", command=lambda: view_tasks(tasks, listbox))
view_button.pack(side=tk.LEFT, fill=tk.X, expand=True)
exit_button = tk.Button(root, text="Exit", command=root.quit)
exit_button.pack(side=tk.LEFT, fill=tk.X, expand=True)
root.mainloop()
if __name__ == "__main__":
main_menu()
The error I get when trying to run it in terminal or the exe file that I created using pyinstaller:
TypeError: main_menu() missing 2 required positional arguments: ‘tasks’ and ‘Listbox’
I have tried to ask ai for help but it just gives me the same code and the problem is still there.
Seblan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.