Skip to content

Commit

Permalink
Borrar un documento con Python en mongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
programadornovato committed Aug 15, 2020
1 parent b83a184 commit f10e34c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion index.py
Expand Up @@ -55,6 +55,7 @@ def dobleClickTabla(event):
calificacion.insert(0,documento["calificacion"])
crear["state"]="disabled"
editar["state"]="normal"
borrar["state"]="normal"
def editarRegistro():
global ID_ALUMNO
if len(nombre.get())!=0 and len(sexo.get())!=0 and len(calificacion.get())!=0 :
Expand All @@ -72,7 +73,21 @@ def editarRegistro():
mostrarDatos()
crear["state"]="normal"
editar["state"]="disabled"

borrar["state"]="disabled"
def borrarRegistro():
global ID_ALUMNO
try:
idBuscar={"_id":ObjectId(ID_ALUMNO)}
coleccion.delete_one(idBuscar)
nombre.delete(0,END)
sexo.delete(0,END)
calificacion.delete(0,END)
except pymongo.errors.ConnectionFailure as error:
print(error)
crear["state"]="normal"
editar["state"]="disabled"
borrar["state"]="disabled"
mostrarDatos()
ventana=Tk()
tabla=ttk.Treeview(ventana,columns=2)
tabla.grid(row=1,column=0,columnspan=2)
Expand All @@ -98,5 +113,10 @@ def editarRegistro():
editar=Button(ventana,text="Editar alumno",command=editarRegistro,bg="yellow")
editar.grid(row=6,columnspan=2)
editar["state"]="disabled"
#Boton borrar
borrar=Button(ventana,text="Borrar alumno",command=borrarRegistro,bg="red",fg="white")
borrar.grid(row=7,columnspan=2)
borrar["state"]="disabled"

mostrarDatos()
ventana.mainloop()

0 comments on commit f10e34c

Please sign in to comment.