I'M getting error below when I run the following program code. It's with the following function. fileD.write("%\n" % depot.get())

Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__
return self.func(*args)
File "/home/developer/Projects/Head First/Chapter 7/Head-Ex.py", line 7, in save_data
fileD.write("%\n" % depot.get())
ValueError: unsupported format character '
' (0xa) at index 1

from Tkinter import *

# function for save_data button
def save_data():
    fileD = open("deliveries.txt", "a")
    fileD.write("Depot:\n")
    fileD.write("%\n" % depot.get())
    fileD.write("Description:\n")
    fileD.write("%\n" % description.get())
    fileD.write("Address:\n")
    fileD.write("%\n" % address.get("1.0", END))
    depot.delete(0, END)
    description.delete(0, END)
    address.delete("1.0", END)

# create GUI
app = Tk()
app.title("Head-Ex Deliveries")

# create a label
Label(app, text = "Depot:").pack() # add to Tk app window

# create a text entry
depot = Entry(app)
depot.pack()

# create another label
Label(app, text = "Description:").pack()

# create another text entry
description = Entry(app)
description.pack()

# create final label
Label(app, text = "Address:").pack()

# create a text field
address = Text(app)
address.pack()

# create button
Button(app, text = "Save", command = save_data).pack()

# gui loop
app.mainloop()
This article has been dead for over six months. Start a new discussion instead.