Advertisement
Guest User

BBDD Manager

a guest
Oct 15th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.53 KB | Source Code | 0 0
  1. #PRACTICA GUIADA I (Capitulo 59)
  2. from tkinter import *
  3. from tkinter import messagebox
  4. import sqlite3
  5.  
  6. global contador
  7.  
  8. contador=False
  9. contador2=True
  10.  
  11. root=Tk()
  12. root.title("Gestor de BBDD")
  13. root.geometry("500x500")
  14. root.resizable(0,0)
  15. img= PhotoImage(file="ddbb.png")
  16. root.tk.call("wm", "iconphoto", root._w, img)
  17.  
  18. conexion=0
  19.  
  20. menus=Menu(root, bg="white", fg="black")
  21.  
  22. root.config(bg="#2c2f33", menu=menus)
  23.    
  24. #TEXTO
  25.    
  26. Label(root, text="ID:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="130", y="30")
  27. Label(root, text="Nombre:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="70", y="80")
  28. Label(root, text="Apellido:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="70", y="130")
  29. Label(root, text="Contraseña:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="35", y="180")
  30. Label(root, text="Comentarios:", bg="#2c2f33", fg="white", font="Arial 15 bold").place(x="25", y="230")
  31.  
  32. #FUNCIONES
  33.  
  34.  
  35. def connect():
  36.  
  37.     def cerrar():
  38.    
  39.         global root3
  40.    
  41.         root3.destroy()
  42.  
  43.     def conectar(input):
  44.         global valor
  45.         valor=input.get()
  46.         print(valor)
  47.        
  48.         global conexion
  49.         global cursoor
  50.        
  51.         conexion=sqlite3.connect(valor)
  52.         cursoor=conexion.cursor()
  53.        
  54.         try:
  55.             cursoor.execute("""
  56. CREATE TABLE USUARIOS (
  57. ID INTEGER PRIMARY KEY AUTOINCREMENT,
  58. NOMBRE VARCHAR(50),
  59. APELLIDO VARCHAR(50),
  60. PASSWORD VARCHAR(50),
  61. COMENTARIOS VARCHAR(100))
  62. """)
  63.  
  64.             global contador2
  65.             contador2=False
  66.             boxes2()
  67.            
  68.             messagebox.showinfo("Gestor...", "¡BBDD Creada con éxito!")
  69.            
  70.         except:
  71.             messagebox.showwarning("¡Gestor!", f"""La BBDD de nombre "{valor}" ya existe""")
  72.        
  73.     global root3
  74.  
  75.     root3 =Tk()
  76.     root3.title("Conectar...")
  77.     Label(root3, text="introduce el nombre de la base").grid(row=0, column=0)
  78.    
  79.     box=Entry(root3)
  80.     box.grid(row=1, column=0)
  81.    
  82.     boton2=Button(root3, text="Aceptar", command= lambda input=box:[conectar(input), cerrar()])
  83.     boton2.grid(row=2, column=0)
  84.    
  85.     root3.mainloop()
  86.  
  87. def create():
  88.  
  89.     global contador
  90.     contador=True
  91.    
  92.     global lista
  93.     global valor
  94.     global conexion
  95.     global cursoor
  96.    
  97.     cursoor=conexion.cursor()
  98.    
  99.     lista=["hola1", "hola2", "hola3", "hola4"]
  100.    
  101.     cursoor.executemany("INSERT INTO USUARIOS VALUES (NULL, ?, ?, ?, ?)", lista)
  102.    
  103.     conexion.commit()
  104.  
  105.  
  106. def salir():
  107.     valor=messagebox.askquestion("Cerrar gestor...", "¿Seguro quieres salir del gestor?")
  108.     if valor=="yes":
  109.         global root
  110.         global conexion
  111.         conexion.close()
  112.         root.destroy()
  113.     else:
  114.         pass
  115.  
  116. def sobre(): #Esta funcion llama a la ventana emergente de "Sobre la app"
  117.     mensaje=messagebox.showwarning("Sobre el programa...", """Creado por:
  118.  
  119. Franco Gaitán
  120. fran.nesgaitan15@gmail.com
  121. """)
  122.  
  123. def guso():    #Esta funcion llama a la ventana emergente de "Guia de uso"
  124.     global root2
  125.     root2=Tk()
  126.     root2.title("Guia de uso")
  127.     root2.resizable(0,0)
  128.    
  129.     Label(root2, text="1.", font="Arial 13").grid(row=0, column=0)
  130.     Label(root2, text="2.", font="Arial 13").grid(row=2, column=0)
  131.     Label(root2, text="3.", font="Arial 13").grid(row=4, column=0)
  132.     Label(root2, text="4.", font="Arial 13").grid(row=6, column=0)
  133.    
  134.     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)
  135.     Label(root2, text="Rellena los campos que aparecen en la pantalla", font="Arial 13").grid(row=2, column=1, pady=10)
  136.     Label(root2, text="Apreta la opción que quieras usar (Crear, Modificar, Leer, Borrar)", font="Arial 13").grid(row=4, column=1, pady=10)
  137.     Label(root2, text="""Apreta el boton "Aceptar" """, font="Arial 13").grid(row=6, column=1, pady=10)
  138.    
  139.     Button(root2, text="Cerrar Guia", command=root2.destroy).place(x="600", y="140")
  140.    
  141.     root2.mainloop()
  142.    
  143. #BBDD
  144.  
  145.  
  146.  
  147.    
  148. #ENTRYS
  149.  
  150. def boxes2():
  151.  
  152.     idd=Entry(root, width=27)
  153.     idd.place(x="190", y="32")
  154.     if contador==True or contador2==True:
  155.         idd.config(state="disabled")
  156.  
  157.     nombree=Entry(root, width=27)
  158.     nombree.place(x="190", y="82")
  159.     if contador2==True:
  160.         nombree.config(state="disabled")
  161.  
  162.     apellidoo=Entry(root, width=27)
  163.     apellidoo.place(x="190", y="132")
  164.     if contador2==True:
  165.         apellidoo.config(state="disabled")
  166.  
  167.     contrasenaa=Entry(root, width=27)
  168.     contrasenaa.place(x="190", y="182")
  169.     if contador2==True:
  170.         contrasenaa.config(state="disabled")
  171.  
  172.     comentarioss=Text(root,height=10, width=30)
  173.     comentarioss.place(x="190", y="232")
  174.     if contador2==True:
  175.         comentarioss.config(state="disabled")
  176.  
  177. #BOTONES
  178.     createe=Button(root, text="Crear", command= create)
  179.     createe.place(x="50", y="420")
  180.     if contador2==True:
  181.         createe.config(state="disabled")
  182.  
  183.     updatee=Button(root, text="Modificar")
  184.     updatee.place(x="150", y="420")
  185.     if contador2==True:
  186.         updatee.config(state="disabled")
  187.  
  188.     readd=Button(root, text="Leer")
  189.     readd.place(x="275", y="420")
  190.     if contador2==True:
  191.         readd.config(state="disabled")
  192.  
  193.     deletee=Button(root, text="Borrar")
  194.     deletee.place(x="375", y="420")
  195.     if contador2==True:
  196.         deletee.config(state="disabled")
  197.  
  198.     aceptaar=Button(root, text="Aceptar")
  199.     aceptaar.place(x="215", y="460")
  200.     if contador2==True:
  201.         aceptaar.config(state="disabled")
  202.  
  203. def boxes():
  204.  
  205.     idd=Entry(root, width=27)
  206.     idd.place(x="190", y="32")
  207.     if contador==True or contador2==True:
  208.         idd.config(state="disabled")
  209.  
  210.     nombree=Entry(root, width=27)
  211.     nombree.place(x="190", y="82")
  212.     if contador2==True:
  213.         nombree.config(state="disabled")
  214.  
  215.     apellidoo=Entry(root, width=27)
  216.     apellidoo.place(x="190", y="132")
  217.     if contador2==True:
  218.         apellidoo.config(state="disabled")
  219.  
  220.     contrasenaa=Entry(root, width=27)
  221.     contrasenaa.place(x="190", y="182")
  222.     if contador2==True:
  223.         contrasenaa.config(state="disabled")
  224.  
  225.     comentarioss=Text(root,height=10, width=30)
  226.     comentarioss.place(x="190", y="232")
  227.     if contador2==True:
  228.         comentarioss.config(state="disabled", bg="light gray")
  229.  
  230. #BOTONES
  231.     createe=Button(root, text="Crear", command= create)
  232.     createe.place(x="50", y="420")
  233.     if contador2==True:
  234.         createe.config(state="disabled")
  235.  
  236.     updatee=Button(root, text="Modificar")
  237.     updatee.place(x="150", y="420")
  238.     if contador2==True:
  239.         updatee.config(state="disabled")
  240.  
  241.     readd=Button(root, text="Leer")
  242.     readd.place(x="275", y="420")
  243.     if contador2==True:
  244.         readd.config(state="disabled")
  245.  
  246.     deletee=Button(root, text="Borrar")
  247.     deletee.place(x="375", y="420")
  248.     if contador2==True:
  249.         deletee.config(state="disabled")
  250.  
  251.     aceptaar=Button(root, text="Aceptar")
  252.     aceptaar.place(x="215", y="460")
  253.     if contador2==True:
  254.         aceptaar.config(state="disabled")
  255.    
  256. boxes()
  257.    
  258. #MENUS
  259.  
  260.  
  261. #PRIMER MENU
  262. menu1=Menu(menus, tearoff=0)
  263. menu1.add_command(label="Conectar", command=connect)
  264. menu1.add_command(label="Salir", command= salir)
  265.  
  266. #SEGUNDO MENU
  267. menu2=Menu(menus, tearoff=0)
  268. menu2.add_command(label="Sobre la app...", command= sobre)
  269. menu2.add_command(label="Guia de uso", command= guso)
  270.  
  271.  
  272. #CASCADAS
  273. menus.add_cascade(label="BBDD", menu=menu1)
  274.  
  275. menus.add_cascade(label="Ayuda", menu=menu2)
  276.  
  277. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement