GUI输入数据并保存

Posted aWolfMan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()

 

以上是关于GUI输入数据并保存的主要内容,如果未能解决你的问题,请参考以下文章