Page 321 -
P. 321

adding options





                               This is a version of the program that uses radio buttons.
                               You are going to update this program so that it uses an option menu. But the options need to be read
                               from a text file.

                   from tkinter import *

                    def save_data():
                        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(None)
                        description.delete(0, END)
                        description.delete(0, END)
                        address.delete("1.0", END)


                    app = Tk()
                    app.title('Head-Ex Deliveries')
                   Label(app, text = "Depot:").pack()
                    depot = StringVar()
                    depot.set(None)
                    Radiobutton(app, variable = depot, text = "Cambridge, MA", value = "Cambridge, MA").
                    pack()
                    Radiobutton(app, variable = depot, text = "Cambridge, UK", value = "Cambridge, UK").
                    pack()
                    Radiobutton(app, variable = depot, text = "Seattle, WA",   value = "Seattle, WA").
                    pack()
                   Label(app, text = "Description:").pack()
                    description = Entry(app)
                    description.pack()
                   Label(app, text = "Address:").pack()
                    address = Text(app)
                    address.pack()
                    Button(app, text = "Save", command = save_data).pack()
                    app.mainloop()

           286    Chapter 8
   316   317   318   319   320   321   322   323   324   325   326