Advertisement
teslariu

form tkinter

May 11th, 2023
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.12 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. ESTRATEGIA PARA MODELAR UNA SITUACION REAL PARA IMPLEMENTAR UN PROGRAMA
  6.  
  7. Programacion orientada a objetos POO OOP
  8.  
  9. Objetos: es una "cosa", algo con propiedades (adjetivos --> atributos)
  10. que puede hacer cosas (verbos  -> métodos)
  11.  
  12. Clase: es un conjunto de objetos con propiedades en comùn
  13.  
  14. Instancia: es un objeto en particular
  15.  
  16. Los objetos interactuan entre sì enviándose mensajes
  17.  
  18. Ejemplo: quiero simular una veterinaria
  19.  
  20. Clases padres: animales, personas, objetos
  21. clases hijas: animales -> perros, gatos,loros, palomas,
  22.    personas --> vendedor, vet, cliente
  23.    obketos --> alimento, cuchas, prod_limpieza
  24.    
  25. Instancia de clase vet: Dr Juan Gomez
  26. Instancia de clase animal--> perro: RinTinTin
  27.  
  28. Atributos y metodos de perro
  29. Perro.color, Perro.edad, Perro.raza  Ej: RinTinTin.edad = 3
  30. Perro.ladra, Perro.come, Perro.juega
  31.  
  32. Ejemplos en Python
  33. Clases : int, float, str, list, dict, etc...
  34. Instancias de listas: lista = ['Jorge', 1, 23.4]
  35. Metodos de lista: append, insert, clear, ...
  36.  
  37. Programacion gràfica:
  38. Clases: ventanas, botones, iconos, cajas_de_texto, etiquetas
  39. Instancia de una clase ventana: geany
  40. atributos: color de fondo, tipo y tamaño de letra, etc, titulo
  41. metodos: maximizar, minimizar, cerrar, mover
  42.  
  43. TODO LOS OBJETOS DENTRO DE UNA VENTANA SE DENOMINAN WIDGETS
  44.  
  45. """
  46. import tkinter as tk
  47. import pprint as p
  48.  
  49. ###### Parte consola
  50. '''
  51. datos = [
  52.    {"nombre":"Juan Robledo", "email":"rob@gmail.com", "edad":23, "telefono": 11222222},
  53.    {"nombre":"Ana Garcia", "email":"annie@gmail.com", "edad":29, "telefono": 11257922},
  54.    {"nombre":"Ricky Martin", "email":"ricky@gmail.com", "edad":50, "telefono": 11298522},
  55. ]
  56. '''
  57. datos = []
  58.  
  59. def guardar_datos():
  60.     global datos
  61.     nombre = caja_nombre.get()
  62.     email = caja_email.get()
  63.     edad = caja_edad.get()
  64.     telefono = caja_tel.get()
  65.     persona = {"nombre":nombre, "email":email, "edad":edad, "telefono":telefono}
  66.     datos.append(persona)
  67.     p.pprint(f"\n{datos}")
  68.     caja_nombre.delete(0,tk.END)
  69.     caja_email.delete(0,tk.END)
  70.     caja_edad.delete(0,tk.END)
  71.     caja_tel.delete(0,tk.END)
  72.  
  73.  
  74.  
  75.  
  76.  
  77. ###### Parte gráfica
  78.  
  79. ventana = tk.Tk()
  80. ventana.config(width=400, height=300)
  81. ventana.title("Formulario de inscripción")
  82. ventana.resizable(0,0)  # evita redimensionar la ventana
  83.  
  84. #### campo nombre
  85. caja_nombre = tk.Entry()
  86. caja_nombre.place(x=150, y=20, width=200, height=25)
  87.  
  88. etiqueta = tk.Label(text="Nombre")
  89. etiqueta.place(x=40, y=20)
  90.  
  91. #### campo edad
  92. caja_edad = tk.Entry()
  93. caja_edad.place(x=150, y=70, width=200, height=25)
  94.  
  95. etiqueta = tk.Label(text="Edad")
  96. etiqueta.place(x=40, y=70)
  97.  
  98. #### campo email
  99. caja_email = tk.Entry()
  100. caja_email.place(x=150, y=120, width=200, height=25)
  101.  
  102. etiqueta = tk.Label(text="Email")
  103. etiqueta.place(x=40, y=120)
  104.  
  105. #### campo telefono
  106. caja_tel = tk.Entry()
  107. caja_tel.place(x=150, y=170, width=200, height=25)
  108.  
  109. etiqueta = tk.Label(text="Teléfono")
  110. etiqueta.place(x=40, y=170)
  111.  
  112. ##### botón
  113. boton = tk.Button(text="Guardar",command=guardar_datos)
  114. boton.place(x=150, y=220, width=100, height=40)
  115.  
  116. ventana.mainloop()
  117.  
  118.  
  119.  
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement