Page 302 -
P. 302

guis and data




                                                The Save button on the interface is going to call a function called
                                                save_data(). The function will append the data from the GUI
                                                to the end of the deliveries.txt file formatted like this:



                                               Depot:
                                               Seattle, WA
                                               Description:
                                               Books
                                               Address:
                                               1 Main Street
                                               Anytown
                                               WA



                  Then it will need to clear the fields on the form ready for the next record to be entered. The function will
                  have to appear in the program before the GUI code. You were to write the code for the function here:
                      Your code may look a                    Append the text to the end of the file,
                      little different.                       just as you did when we wrote the POS

                                           def save_data():    programs for the Health Club.
                                               fileD = open(“deliveries.txt", “a")


                       get() returns the       fileD.write(“Depot:\n")
                       contents of an Entry       fileD.write(“%s\n" % depot.get())
                       field.
                                               fileD.write(“Description:\n")
                                               fileD.write(“%s\n" % description.get())
                         get(“1.0", END)
                          returns the          fileD.write(“Address:\n")
                          contents of a T ext       fileD.write(“%s\n" % address.get(“1.0", END))
                          field.
                                               depot.delete(0, END)
                                               description.delete(0, END)
                       Don't forget to clear
                       the fields after saving       address.delete(“1.0", END)
                       the data.
                                                                  This means “1st row, 0th column." Remember
                                                                  that rows start at 1 and columns from 0.




                                                                                       you are here 4    267
   297   298   299   300   301   302   303   304   305   306   307