Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- import tkinter as tk
- ventana = tk.Tk() # tk.Nombre_del_widget()
- ventana.config(width=400, height=300)
- ventana.title("Mi primera aplicación de escritorio")
- def imprimir_lista():
- if len(alumnos) > 0:
- print("Lista de alumnos:")
- for nombre, cursos in alumnos.items():
- print(f"{nombre} - {cursos} cursos")
- else:
- print("No hay ningún alumno inscripto")
- def agregar_a_lista():
- alumnos[caja_nombre.get()] = int(caja_cursos.get())
- print("Has ingresado el alumno correctamente.")
- def ver_cursos():
- nombre = caja_nombre.get()
- lista_nombres = list(alumnos.keys())
- if nombre in lista_nombres:
- print(f"El alumno {nombre} tiene {alumnos[nombre]} cursos")
- else:
- print(f"No existe el alumno {nombre}")
- alumnos ={} # alumnos = {"Pepe":3, "Juan":5, "Ana":2}
- boton = tk.Button(text="Ver lista de alumnos", command=imprimir_lista)
- boton.place(x=20, y=20, width=150, height=30)
- etiqueta = tk.Label(text="Nombre de alumno:")
- etiqueta.place(x=20, y=90)
- caja_nombre = tk.Entry()
- caja_nombre.place(x=140, y=90, width=200, height=25)
- etiqueta = tk.Label(text="Cursos:")
- etiqueta.place(x=20, y=140)
- caja_cursos = tk.Entry()
- caja_cursos.place(x=140, y=140, width=100, height=25)
- boton = tk.Button(text="Agregar a la lista", command=agregar_a_lista)
- boton.place(x=20, y=190, width=150, height=30)
- boton = tk.Button(text="Ver cantidad de cursos", command=ver_cursos)
- boton.place(x=220, y=190, width=150, height=30)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment