Advertisement
teslariu

integrador con tkinter

Nov 29th, 2022
1,075
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import tkinter as tk
  5.  
  6. alumnos = {}
  7.  
  8. def ver_lista():
  9.     global alumnos
  10.     if alumnos:
  11.         print("\nLista de alumnos:")
  12.         for k,v in alumnos.items():
  13.             print(f"Nombre: {k} - Cursos: {v}")
  14.     else:
  15.         print("No existen alumnos")
  16.        
  17.    
  18.    
  19. def ver_cursos():
  20.     global alumnos
  21.     caja_cursos.delete(0,tk.END)
  22.     hallado = False
  23.     nombre = caja_nombre.get()
  24.     for k,v in alumnos.items():
  25.         if k == nombre:
  26.             caja_cursos.insert(0,alumnos[nombre])
  27.             hallado = True
  28.             break
  29.     if not hallado:
  30.             caja_cursos.insert(0,"No existe el alumno")
  31.  
  32.  
  33.  
  34. def agregar():
  35.     global alumnos
  36.     nombre = caja_nombre.get()
  37.     cursos = int(caja_cursos.get())
  38.     alumnos[nombre] = cursos
  39.  
  40.  
  41. ventana = tk.Tk()
  42. ventana.title("PROYECTO INTEGRADOR")
  43. ventana.config(width=350, height=350)
  44.  
  45.  
  46. # botones
  47. boton = tk.Button(text="Ver lista de alumnos", command=ver_lista)
  48. boton.place(x=20, y=20, width=130, height=30)
  49.  
  50. boton = tk.Button(text="Ver cantidad de cursos", command=ver_cursos)
  51. boton.place(x=150, y=200, width=130, height=30)
  52.  
  53. boton = tk.Button(text="Agregar a la lista", command=agregar)
  54. boton.place(x=20, y=200, width=100, height=30)
  55.  
  56.  
  57. # campo nombre del alumno
  58. etiqueta = tk.Label(text="Nombre del alumno")
  59. etiqueta.place(x=20, y=100)
  60. caja_nombre = tk.Entry()
  61. caja_nombre.place(x=150, y=100, width=150, height=25)
  62.  
  63. # campo cursos
  64. etiqueta = tk.Label(text="Cursos")
  65. etiqueta.place(x=80, y=140)
  66. caja_cursos = tk.Entry()
  67. caja_cursos.place(x=150, y=140, width=150, height=25)
  68.  
  69.  
  70. ventana.mainloop()
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.    
  79.  
  80.  
  81.  
  82.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement