Page 334 -
P. 334
exceptions and message boxes
Exception Magnets
Assemble the code to handle an exception in the save_data()
function. The exception handler needs to display the details of the
exception in the title bar of the window. Note: remember to indent
the code in the exception handler, in addition to the code in the
try block.
fileD = open("deliveries.txt", "a")
fileD.write("Depot:\n")
fileD.write("%s\n" % depot.get())
fileD.write("Description:\n")
fileD.write("%s\n" % description.get())
fileD.write("Address:\n")
fileD.write("%s\n" % address.get("1.0", END))
depot.set("")
description.delete(0, END)
description.delete(0, END)
address.delete("1.0", END)
def save_data():
app.title(
"Can’t write to the file %s"
ex
)
as
except Exception
ex: %
try:
you are here 4 299