这是我的代码:
def openphonebook():
root.withdraw()
global SaveName, SavePhone
def add_contact():
SaveName = InputtedName.get()
SavePhone = InputtedNumber.get()
try:
integer_result = int(SavePhone)
except ValueError:
tkMessageBox.showinfo("Error", "Not a Valid Number")
else:
addressBook = open(username +".c", "a")
addressBook.write(SaveName + " " + SavePhone + "\n")
addressBook.close()
ShowContent.insert(END, SaveName + ' ' + SavePhone)
def delete_contact():
selection = ShowContent.curselection()
ShowContent.delete(selection[0])
AddressBook = Tk()
AddressBook.geometry("700x700")
AddressBook.configure(background="#00d6d6")
Inputs = Frame(AddressBook)
Inputs.configure(background="#00d6d6")
Inputs.pack()
Label(Inputs, text="Name:", bg="#00d6d6").grid(row=0, column=0, sticky=W, pady=15)
InputtedName = StringVar()
nameofPerson = Entry(Inputs, textvariable=InputtedName, highlightbackground="#00d6d6")
nameofPerson.grid(row=0, column=1, sticky=W)
Label(Inputs, text="Phone:", bg="#00d6d6").grid(row=4, column=0, sticky=W, pady=15)
InputtedNumber = StringVar()
phoneofPerson = Entry(Inputs, textvariable=InputtedNumber, highlightbackground="#00d6d6")
phoneofPerson.grid(row=4, column=1, sticky=W)
ButtonLayout = Frame(AddressBook)
ButtonLayout.pack()
ButtonLayout.configure(bg="#00d6d6", pady=25)
AddButton = Button(ButtonLayout, text=" Add Contact ", highlightbackground="#00d6d6", command=add_contact)
UpdateButton = Button(ButtonLayout, text="Update Contact", highlightbackground="#00d6d6")
DeleteButton = Button(ButtonLayout, text="Delete Contact", highlightbackground="#00d6d6", command=delete_contact)
AddButton.pack(side=LEFT, padx=3)
UpdateButton.pack(side=LEFT, padx=3)
DeleteButton.pack(side=LEFT, padx=3)
global SaveName, SavePhone
DisplayedDetails = Frame(AddressBook)
DisplayedDetails.pack()
Scrolling = Scrollbar(DisplayedDetails, orient=VERTICAL)
global ShowContent
ShowContent = Listbox(DisplayedDetails, yscrollcommand=Scrolling.set, height=20, width=50, )
Scrolling.config(command=ShowContent.yview)
Scrolling.pack(side=RIGHT, fill=Y)
ShowContent.pack(side=LEFT, fill=BOTH, expand=1)
AddressBook.mainloop()
root.mainloop()
至于错误,我得到一个数字,如“336783”我仍然出于某种原因仍然设法得到消息框任何想法如何解决它。任何帮助将不胜感激。