Page 323 -
P. 323

options added





                               This is a version of the program that uses radio buttons.
                               You needed to update this program so that it used an option menu. But the options
                                were 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()


           288    Chapter 8
   318   319   320   321   322   323   324   325   326   327   328