teslariu

integrador final

Apr 15th, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Métodos para diseñar entornos gráficos
  5. # place usa coordenadas (x,y)
  6. # pack que escribe cada widget en relación al anterior(a la derecha, arriba)
  7. # grid: se escriben widgets en una grilla (fila1, columna 1, etc)
  8. # estos metodos no se pueden mezclar. Nosotros trabajaremos solamente
  9. # con place
  10. # a partir de TCL/Tk --> python crea la librería tkinter
  11.  
  12. import tkinter as tk
  13.  
  14. def ver_lista():
  15.     print("Lista de alumnos")
  16.     for nombre,cursos in alumnos.items():
  17.         print(f"{nombre} - {cursos} cursos")
  18.    
  19. def agregar_alumno():
  20.     nombre = caja_nombre.get()
  21.     cursos = caja_cursos.get()
  22.     alumnos[nombre] = cursos
  23.    
  24. def ver_cursos():
  25.     nombre = caja_nombre.get()
  26.     cursos = alumnos[nombre]
  27.     print(f"Cursos: {cursos}")
  28.  
  29.  
  30. ###### creo una ventana ###############
  31. ventana = tk.Tk()
  32. ventana.config(width=600, height=450)
  33. ventana.title("Proyecto Integrador")
  34.  
  35. alumnos = {}
  36.  
  37.  
  38. ################## campos: nombre alumno y cursos #############
  39.  
  40. # nombre del alumno
  41. caja_nombre = tk.Entry()
  42. caja_nombre.place(x=150, y=80, width=200, height=25)
  43. etiqueta = tk.Label(text="Nombre alumno")
  44. etiqueta.place(x=30, y=80)
  45.  
  46. # cursos
  47. caja_cursos = tk.Entry()
  48. caja_cursos.place(x=150, y=140, width=50, height=25)
  49. etiqueta = tk.Label(text="Cursos")
  50. etiqueta.place(x=30, y=150)
  51.  
  52. ########## botones #################
  53. boton = tk.Button(text="Ver lista de alumnos", command = ver_lista)
  54. boton.place(x=30, y=10, width=150, height=30)
  55.  
  56. boton = tk.Button(text="Ver cursos", command = ver_cursos)
  57. boton.place(x=250, y=200, width=100, height=30)
  58.  
  59. boton = tk.Button(text="Agregar a la lista", command = agregar_alumno)
  60. boton.place(x=30, y=200, width=150, height=30)
  61.  
  62.  
  63.  
  64. ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment