So basically I have my code get all the input from the basketballs, dodgeballs, rackets tennisballs etc from the user, I can log them into a InvenData.txt file but how would I actually keep them their after the application closes? Im using datetime, is there also a method that I can use that identifies months? This is basically how I want it to work...
Fill out the table (already done, receives input) then, take that input and orderly put it into a file (Done that as well and it saves the month in the data as well) And then I want it to stay there. And AS LONG as they are still in THAT Current month it will update THAT Month's data and when the month changes, throw, it will throw the data down into the same format as the last month, but just further down the Data file
file.write("Basketballs: " + ballEntry.get() + "\n")
file.write("Dodgeballs: " + dodgeEntry.get() + "\n")
file.write("Rackets: " + racketEntry.get() + "\n")
file.write("Tenisballs: " + TenisballlEntry.get() + "\n")
file.write("Total: " + totalFile + "\n")
file.write("Last updated on: " + dateTimeFile + "\n")
The file looks like this when all the user puts their input in
Basketballs: 423
Dodgeballs: 234
Rackets: 253
Tenisballs: 235
Total: 1145
Last updated on: 2020-01-14
EXAMPLE OF WHAT I'D WANT IT TO DO THE NEXT MONTH
Basketballs: 4223
Dodgeballs: 23324
Rackets: 2453
Tenisballs: 2335
Total: 11435
Last updated on: 2020-02-01
Thanks fore reading!
with open('InvenData.txt', 'r') as f:
filestring1 = file.write("Current Position: %d" % (fileLinePos) + "\n")
filestring2 = file.write("Basketballs: " + ballEntry.get() + "\n")
filestring3 = file.write("Dodgeballs: " + dodgeEntry.get() + "\n")
filestring4 = file.write("Rackets: " + racketEntry.get() + "\n")
filestring5 = file.write("Tenisballs: " + TenisballlEntry.get() + "\n")
filestring6 = file.write("Total: " + totalFile + "\n")
filestring7 = file.write(timeString)
file.close()
list = [filestring1, filestring2, filestring3, filestring4, filestring5, filestring6, filestring7]
lines = list(f)
for line in lines:
file.write(line)
print("Data has been registered successfully!")
messagebox.showinfo('Success!', 'Data added to data centre successfully!')