teslariu

integrados

Jan 18th, 2021
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import tkinter as tk  
  5.  
  6. ventana = tk.Tk() # tk.Nombre_del_widget()
  7. ventana.config(width=400, height=300)
  8. ventana.title("Mi primera aplicación de escritorio")
  9.  
  10. def imprimir_lista():
  11.     if len(alumnos) > 0:
  12.         print("Lista de alumnos:")
  13.         for nombre, cursos in alumnos.items():
  14.             print(f"{nombre} - {cursos} cursos")
  15.     else:
  16.         print("No hay ningún alumno inscripto")
  17.    
  18. def agregar_a_lista():
  19.     alumnos[caja_nombre.get()] = int(caja_cursos.get())
  20.     print("Has ingresado el alumno correctamente.")
  21.    
  22.    
  23. def ver_cursos():
  24.     nombre = caja_nombre.get()
  25.     lista_nombres = list(alumnos.keys())
  26.     if nombre in lista_nombres:
  27.         print(f"El alumno {nombre} tiene {alumnos[nombre]} cursos")
  28.     else:
  29.         print(f"No existe el alumno {nombre}")
  30.  
  31. alumnos ={} # alumnos = {"Pepe":3, "Juan":5, "Ana":2}
  32.  
  33. boton = tk.Button(text="Ver lista de alumnos", command=imprimir_lista)
  34. boton.place(x=20, y=20, width=150, height=30)
  35.  
  36. etiqueta = tk.Label(text="Nombre de alumno:")
  37. etiqueta.place(x=20, y=90)
  38.  
  39. caja_nombre = tk.Entry()
  40. caja_nombre.place(x=140, y=90, width=200, height=25)
  41.  
  42. etiqueta = tk.Label(text="Cursos:")
  43. etiqueta.place(x=20, y=140)
  44.  
  45. caja_cursos = tk.Entry()
  46. caja_cursos.place(x=140, y=140, width=100, height=25)
  47.  
  48. boton = tk.Button(text="Agregar a la lista", command=agregar_a_lista)
  49. boton.place(x=20, y=190, width=150, height=30)
  50.  
  51. boton = tk.Button(text="Ver cantidad de cursos", command=ver_cursos)
  52. boton.place(x=220, y=190, width=150, height=30)
  53.  
  54.  
  55.  
  56. ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment