Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Métodos para diseñar entornos gráficos
- # place usa coordenadas (x,y)
- # pack que escribe cada widget en relación al anterior(a la derecha, arriba)
- # grid: se escriben widgets en una grilla (fila1, columna 1, etc)
- # estos metodos no se pueden mezclar. Nosotros trabajaremos solamente
- # con place
- # a partir de TCL/Tk --> python crea la librería tkinter
- import tkinter as tk
- def ver_lista():
- print("Lista de alumnos")
- for nombre,cursos in alumnos.items():
- print(f"{nombre} - {cursos} cursos")
- def agregar_alumno():
- nombre = caja_nombre.get()
- cursos = caja_cursos.get()
- alumnos[nombre] = cursos
- def ver_cursos():
- nombre = caja_nombre.get()
- cursos = alumnos[nombre]
- print(f"Cursos: {cursos}")
- ###### creo una ventana ###############
- ventana = tk.Tk()
- ventana.config(width=600, height=450)
- ventana.title("Proyecto Integrador")
- alumnos = {}
- ################## campos: nombre alumno y cursos #############
- # nombre del alumno
- caja_nombre = tk.Entry()
- caja_nombre.place(x=150, y=80, width=200, height=25)
- etiqueta = tk.Label(text="Nombre alumno")
- etiqueta.place(x=30, y=80)
- # cursos
- caja_cursos = tk.Entry()
- caja_cursos.place(x=150, y=140, width=50, height=25)
- etiqueta = tk.Label(text="Cursos")
- etiqueta.place(x=30, y=150)
- ########## botones #################
- boton = tk.Button(text="Ver lista de alumnos", command = ver_lista)
- boton.place(x=30, y=10, width=150, height=30)
- boton = tk.Button(text="Ver cursos", command = ver_cursos)
- boton.place(x=250, y=200, width=100, height=30)
- boton = tk.Button(text="Agregar a la lista", command = agregar_alumno)
- boton.place(x=30, y=200, width=150, height=30)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment