GUI输入数据并保存

from tkinter import *

def write_to_file():
    fileContent = open("deliveries.txt","a")
    fileContent.write(depot.get()+"\n")
    fileContent.write(description.get()+"\n")
    fileContent.write(address.get("1.0",END)+"\n")
    fileContent.close()
    depot.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 = Entry(app)
depot.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",width = 10,command = write_to_file).pack()
app.mainloop()

 

转载于:https://www.cnblogs.com/liuyang92/p/7414192.html

你可能感兴趣的:(GUI输入数据并保存)