【python】通讯录制作

Address book

from tkinter import *
import tkinter.messagebox

def save_data():
    try:
        fileD=open("通讯录.txt","a") 
        fileD.write("姓名:")  
        fileD.write("%s\n" % name.get())  
        fileD.write("联系电话:")  
        fileD.write("%s\n" % phonenumber.get())  
        fileD.write("邮箱地址:")  
        fileD.write("%s\n\n" % mailaddress.get())
        name.delete(0,END)
        phonenumber.delete(0,END)
        mailaddress.delete(0,END)
    except Exception as ex:
        tkinter.messagebox.showerror("Error!","Can't write to the file\n%s"%ex)

app=Tk()
app.title('Address Book')
Label(app,text="Name:").pack()
name=Entry(app)
name.pack()

Label(app,text="PhoneNumber:").pack()
phonenumber=Entry(app)
phonenumber.pack()

Label(app,text="MailAddress:").pack()
mailaddress=Entry(app)
mailaddress.pack()

Button(app,text="save",command=save_data).pack()
app.mainloop()

你可能感兴趣的:(【python】通讯录制作)