Head First Programming - headex.py

 1 from tkinter import *
 2 def save_data():
 3     fileD = open("deliveries.txt", "a")
 4     fileD.write("Depot:\n")
 5     fileD.write("%s\n" % depot.get())
 6     fileD.write("Description:\n")
 7     fileD.write("%s\n" % description.get())
 8     fileD.write("Address:\n")
 9     fileD.write("%s\n" % address.get("1.0", END))
10     depot.set(None)
11     description.delete(0, END)
12     address.delete("1.0", END)
13 def read_depots(file):
14     depot = []
15     depots = open(file)
16     for line in depots:
17         depot.append(line.rstrip())
18     depots.close()
19     return depot
20 app = Tk()
21 app.title('Head-Ex Deliveries')
22 Label(app, text = "Depot:").pack()
23 depot = StringVar()
24 depot.set(None)
25 options = read_depots("depots.txt")
26 OptionMenu(app, depot, *options).pack()
27 Label(app, text = "Description:").pack()
28 description = Entry(app)
29 description.pack()
30 Label(app, text = "Address:").pack()
31 address = Text(app)
32 address.pack()
33 Button(app, text = "Save", command = save_data).pack()
34 app.mainloop()

 

posted on 2013-01-07 17:35  mybluecode  阅读(213)  评论(0编辑  收藏  举报