一个想法 为什么此代码将空行插入数据库sqlite3
我是python编程的新手,也是tkinter的新手。
def Database(): #Database Connection
global conn, cursor
conn = sqlite3.connect("carrent.db")
cursor = conn.cursor()
def Add_New_Car():
screen2 =Toplevel(Home)
screen2.configure(background='turquoise')
screen2.title("Add New Car")
screen2.geometry("500x450")
name = StringVar()
Reg_number=StringVar()
Model = StringVar()
Meter_Reading = StringVar()
Status = StringVar()
Label(screen2, text="Name", width=45).pack()
Entry(screen2,textvariable = name).pack()
Label(screen2, text="Registration Number *",width=45,).pack()
Entry(screen2,textvariable = Reg_number).pack()
Label(screen2, text="Model", width=45).pack()
Entry(screen2,textvariable = Model).pack()
Label(screen2, text="Meter Reading",width=45,).pack()
Entry(screen2,textvariable = Meter_Reading).pack()
Label(screen2, text="Status", width=45).pack()
Entry(screen2,textvariable = Status).pack()
b1=Button(screen2, text="Add", width=45,
bg="blue",command=Add_Car_Data)
b1.pack()
def Add_Car_Data():
Database()
cursor.execute("INSERT INTO `cars` VALUES(NULL,?,?,?,?,?)",
(str(name.get()) ,str(Reg_number.get()),str(Model.get()),
str(Meter_Reading.get()),str(Status.get())))
conn.commit()
cursor.close()
conn.close()
答案 0 :(得分:0)
尝试一下:
将汽车的默认值插入