Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PRACTICA GUIADA I (Capitulo 59)
- from tkinter import *
- from tkinter import messagebox
- import sqlite3
- global contador
- contador=False
- contador2=True
- root=Tk()
- root.title("Gestor de BBDD")
- root.geometry("500x500")
- root.resizable(0,0)
- img= PhotoImage(file="ddbb.png")
- root.tk.call("wm", "iconphoto", root._w, img)
- conexion=0
- menus=Menu(root, bg="white", fg="black")
- root.config(bg="#2c2f33", menu=menus)
- #TEXTO
- Label(root, text="ID:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="130", y="30")
- Label(root, text="Nombre:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="70", y="80")
- Label(root, text="Apellido:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="70", y="130")
- Label(root, text="Contraseña:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="35", y="180")
- Label(root, text="Comentarios:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="25", y="230")
- #FUNCIONES
- def connect():
- def cerrar():
- global root3
- root3.destroy()
- def conectar(input):
- global valor
- valor=input.get()
- print(valor)
- global conexion
- global cursoor
- conexion=sqlite3.connect(valor)
- cursoor=conexion.cursor()
- try:
- cursoor.execute("""
- CREATE TABLE USUARIOS (
- ID INTEGER PRIMARY KEY AUTOINCREMENT,
- NOMBRE VARCHAR(50),
- APELLIDO VARCHAR(50),
- PASSWORD VARCHAR(50),
- COMENTARIOS VARCHAR(100))
- """)
- global contador2
- contador2=False
- boxes2()
- messagebox.showinfo("Gestor...", "¡BBDD Creada con éxito!")
- except:
- messagebox.showwarning("¡Gestor!", f"""La BBDD de nombre "{valor}" ya existe""")
- global root3
- root3 =Tk()
- root3.title("Conectar...")
- Label(root3, text="introduce el nombre de la base").grid(row=0, column=0)
- box=Entry(root3)
- box.grid(row=1, column=0)
- boton2=Button(root3, text="Aceptar", command= lambda input=box:[conectar(input), cerrar()])
- boton2.grid(row=2, column=0)
- root3.mainloop()
- def create():
- global contador
- contador=True
- global lista
- global valor
- global conexion
- global cursoor
- cursoor=conexion.cursor()
- lista=["hola1", "hola2", "hola3", "hola4"]
- cursoor.executemany("INSERT INTO USUARIOS VALUES (NULL, ?, ?, ?, ?)", lista)
- conexion.commit()
- def salir():
- valor=messagebox.askquestion("Cerrar gestor...", "¿Seguro quieres salir del gestor?")
- if valor=="yes":
- global root
- global conexion
- conexion.close()
- root.destroy()
- else:
- pass
- def sobre(): #Esta funcion llama a la ventana emergente de "Sobre la app"
- mensaje=messagebox.showwarning("Sobre el programa...", """Creado por:
- Franco Gaitán
- fran.nesgaitan15@gmail.com
- """)
- def guso(): #Esta funcion llama a la ventana emergente de "Guia de uso"
- global root2
- root2=Tk()
- root2.title("Guia de uso")
- root2.resizable(0,0)
- Label(root2, text="1.", font="Arial 13").grid(row=0, column=0)
- Label(root2, text="2.", font="Arial 13").grid(row=2, column=0)
- Label(root2, text="3.", font="Arial 13").grid(row=4, column=0)
- Label(root2, text="4.", font="Arial 13").grid(row=6, column=0)
- Label(root2, text="""Dirigete a la pestaña "BBDD" de la parte superior izquierda y selecciona "conectar" """, font="Arial 13").grid(row=0, column=1, pady=10, ipadx=15)
- Label(root2, text="Rellena los campos que aparecen en la pantalla", font="Arial 13").grid(row=2, column=1, pady=10)
- Label(root2, text="Apreta la opción que quieras usar (Crear, Modificar, Leer, Borrar)", font="Arial 13").grid(row=4, column=1, pady=10)
- Label(root2, text="""Apreta el boton "Aceptar" """, font="Arial 13").grid(row=6, column=1, pady=10)
- Button(root2, text="Cerrar Guia", command=root2.destroy).place(x="600", y="140")
- root2.mainloop()
- #BBDD
- #ENTRYS
- def boxes2():
- idd=Entry(root, width=27)
- idd.place(x="190", y="32")
- if contador==True or contador2==True:
- idd.config(state="disabled")
- nombree=Entry(root, width=27)
- nombree.place(x="190", y="82")
- if contador2==True:
- nombree.config(state="disabled")
- apellidoo=Entry(root, width=27)
- apellidoo.place(x="190", y="132")
- if contador2==True:
- apellidoo.config(state="disabled")
- contrasenaa=Entry(root, width=27)
- contrasenaa.place(x="190", y="182")
- if contador2==True:
- contrasenaa.config(state="disabled")
- comentarioss=Text(root,height=10, width=30)
- comentarioss.place(x="190", y="232")
- if contador2==True:
- comentarioss.config(state="disabled")
- #BOTONES
- createe=Button(root, text="Crear", command= create)
- createe.place(x="50", y="420")
- if contador2==True:
- createe.config(state="disabled")
- updatee=Button(root, text="Modificar")
- updatee.place(x="150", y="420")
- if contador2==True:
- updatee.config(state="disabled")
- readd=Button(root, text="Leer")
- readd.place(x="275", y="420")
- if contador2==True:
- readd.config(state="disabled")
- deletee=Button(root, text="Borrar")
- deletee.place(x="375", y="420")
- if contador2==True:
- deletee.config(state="disabled")
- aceptaar=Button(root, text="Aceptar")
- aceptaar.place(x="215", y="460")
- if contador2==True:
- aceptaar.config(state="disabled")
- def boxes():
- idd=Entry(root, width=27)
- idd.place(x="190", y="32")
- if contador==True or contador2==True:
- idd.config(state="disabled")
- nombree=Entry(root, width=27)
- nombree.place(x="190", y="82")
- if contador2==True:
- nombree.config(state="disabled")
- apellidoo=Entry(root, width=27)
- apellidoo.place(x="190", y="132")
- if contador2==True:
- apellidoo.config(state="disabled")
- contrasenaa=Entry(root, width=27)
- contrasenaa.place(x="190", y="182")
- if contador2==True:
- contrasenaa.config(state="disabled")
- comentarioss=Text(root,height=10, width=30)
- comentarioss.place(x="190", y="232")
- if contador2==True:
- comentarioss.config(state="disabled", bg="light gray")
- #BOTONES
- createe=Button(root, text="Crear", command= create)
- createe.place(x="50", y="420")
- if contador2==True:
- createe.config(state="disabled")
- updatee=Button(root, text="Modificar")
- updatee.place(x="150", y="420")
- if contador2==True:
- updatee.config(state="disabled")
- readd=Button(root, text="Leer")
- readd.place(x="275", y="420")
- if contador2==True:
- readd.config(state="disabled")
- deletee=Button(root, text="Borrar")
- deletee.place(x="375", y="420")
- if contador2==True:
- deletee.config(state="disabled")
- aceptaar=Button(root, text="Aceptar")
- aceptaar.place(x="215", y="460")
- if contador2==True:
- aceptaar.config(state="disabled")
- boxes()
- #MENUS
- #PRIMER MENU
- menu1=Menu(menus, tearoff=0)
- menu1.add_command(label="Conectar", command=connect)
- menu1.add_command(label="Salir", command= salir)
- #SEGUNDO MENU
- menu2=Menu(menus, tearoff=0)
- menu2.add_command(label="Sobre la app...", command= sobre)
- menu2.add_command(label="Guia de uso", command= guso)
- #CASCADAS
- menus.add_cascade(label="BBDD", menu=menu1)
- menus.add_cascade(label="Ayuda", menu=menu2)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement