Alright so I ended up figuring it out myself through the following changes:
- I made a new variable called "entries" containing a list of the inputs so that the append function would recognize it as a function.
- I changed the double '\' to a single '/' in the 'filepath' variable to resolve the 'NoneType' error.
I'm not sure if a combination of these 2 solutions fixed it or it was a single solution that fixed it, but nonetheless it's done the job. I'll leave it to the people who are more experienced with python to answer that :)
P.S: I'm pretty sure the code can look a lot better and simpler, but again, I'm a python newbee... at least it works :D
New and Working Code:
#Libraries that were used
import tkinter, os, openpyxl
from openpyxl import *
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
def submit_form():# submit form
StaffIdDropdown = staff_id_dropdown.get()
StaffNameEntry = staff_name_entry.get()
StaffTitleEntry = staff_title_entry.get()
DepartmentEntry = department_entry.get()
CardTypeDropdown = card_type_dropdown.get()
SafetyFunctionDropdown = safety_function_dropdown.get()
SafetyStandardDropdown = safety_standard_dropdown.get()
ManualTextEntry = manualy_text_entry.get("1.0",'end-1c')
entries = [CardTypeDropdown, StaffIdDropdown, StaffNameEntry, StaffTitleEntry, DepartmentEntry, SafetyFunctionDropdown, SafetyStandardDropdown, ManualTextEntry]
print("The form has been submitted successfully with the following contents:\n", StaffNameEntry.upper(), " with the staff ID of ", StaffIdDropdown.upper(),
" and a title of ", StaffTitleEntry.upper(), " belonging to the ", DepartmentEntry.upper(), " Department.")
print("-------------------------------------------------------------------------------------------------------")
main_filepath = "C:/Users/JadJackHanna/OneDrive - Terminals Holding/Terminals Holding LLC/Application Python/ApplicationData.xlsx"
if not os.path.exists(main_filepath):
workbook = openpyxl.Workbook()
sheet = workbook.active
form_headings = ["Card Type", "Staff ID", "Staff Name", "Staff Title", "Department",
"Safety Function", "Safety Standard", "Brief Description of the Incident"]
sheet.append(form_headings)
sheet.append(entries)
workbook.save(main_filepath)
else:
workbook = openpyxl.load_workbook(main_filepath)
sheet = workbook.active
sheet.append(entries)
workbook.save(main_filepath)
staff_id_dropdown.set('')
staff_name_entry.delete(0, 'end')
staff_title_entry.delete(0, 'end')
department_entry.delete(0, 'end')
card_type_dropdown.set('')
safety_function_dropdown.set('')
safety_standard_dropdown.set('')
manualy_text_entry.delete('1.0', tkinter.END)
# Confirmation Box
messagebox.showinfo(title="Success!", message="The form as been submitted and saved!")