我只是在这里疯了吗?这是前几天运行的,现在当我尝试运行它时,出现以下错误。代码是否可能存在其他问题,这就是它没有运行的原因,还是特别说明我错误地缩进了第 10 行?我对此有点迷茫。
python phonebookapp.py
File "phonebookapp.py", line 10
self.text.pack()
^
IndentationError: unexpected indent
?
from Tkinter import *
import sqlite3
class Hello():
def __init__(self, master):
frame=Frame(master, width=80, height=50)
frame.pack()
self.text = Label(frame, text=" ")
self.text.pack()
self.text.grid(row=0, sticky=W)
self.lab = Label(frame, text="name")
self.lab.pack(side=LEFT)
self.lab.grid(row=1)
self.TextField = Entry(frame, text = "name", width=30)
self.TextField.insert(0, "Enter Name")
self.TextField.pack()
self.TextField.grid(row=1)
self.TextField.bind("Button-1", clearEvent)
self.TextField2 = Entry(frame, text = "age", width=30)
self.TextField2.insert(0, "Enter Age")
self.TextField2.pack()
self.TextField2.grid(row=2)
self.TextField3 = Entry(frame, text = "phone", width=30)
self.TextField3.insert(0, "Enter Phone #")
self.TextField3.pack()
self.TextField3.grid(row=3)
self.TextField4 = Entry(frame, text = "fblink", width=30)
self.TextField4.insert(0, "Enter Facebook Link")
self.TextField4.pack()
self.TextField4.grid(row=4)
self.btn=Button(frame, text='Add', command=self.add_note)
self.btn.pack()
self.btn.grid(row=5, rowspan=1, sticky="w")
self.showbtn = Button(frame, text='Update', command=self.show_notes)
self.showbtn.pack()
self.showbtn.grid(row=5, rowspan=1, sticky="")
self.delbtn = Button(frame, text='Delete', command=self.del_notes)
self.delbtn.pack()
self.delbtn.grid(row=5, rowspan=1, sticky="e")
self.content=Listbox(master, width=50)
self.content.pack()
def clearEvent(self, event):
self.TextField.delete(0,END)
def add_note(self):
if self.TextField.get() == "":
self.text["text"] = "Please type sumting"
else:
item = self.TextField.get()
item2 = self.TextField2.get()
item3 = self.TextField3.get()
item4 = self.TextField4.get()
conn = sqlite3.connect('phonebook1.db')
c = conn.cursor()
conn.execute('''
CREATE TABLE IF NOT EXISTS people(name TEXT primary key,
age TEXT, phone TEXT, fblink TEXT)''')
c.execute("insert into people values (?, ?, ?, ?)", (item, item2, item3, item4))
conn.commit()
list=c.execute("SELECT * FROM people")
conn.commit()
for row in list:
self.content.insert(END, row)
c.close()
self.TextField.delete(0, END)
self.TextField2.delete(0, END)
self.TextField3.delete(0, END)
self.TextField4.delete(0, END)
def show_notes(self):
conn = sqlite3.connect('phonebook1.db')
c =conn.cursor()
listbox.delete(0, END)
list=c.execute("SELECT * FROM people")
conn.commit()
for row in list:
self.content.insert(END, row)
c.close()
def del_notes(self):
pass
root=Tk()
application = Hello(root)
root.mainloop()