teslariu

tkinter

Jul 14th, 2022
1,211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # place
  5. import tkinter as tk
  6. from tkinter import ttk
  7. from tkinter import messagebox
  8. from pprint import pprint
  9.  
  10. personas = []
  11. # personas = [{"nombre": Juan, "email":"juands", "tel":4564546}]
  12.  
  13.  
  14. def guardar():
  15.     global personas
  16.     nombre = caja_nombre.get()
  17.     email = caja_email.get()
  18.     tel = caja_tel.get()
  19.     persona = {"nombre":nombre, "email":email, "tel":tel}
  20.     personas.append(persona)
  21.     print()
  22.     pprint(personas)
  23.     caja_email.delete(0,tk.END)
  24.     caja_nombre.delete(0,tk.END)
  25.     caja_tel.delete(0,tk.END)
  26.  
  27. def sel_lista():
  28.     eleccion = lista.get(lista.curselection())
  29.     print(eleccion)
  30.  
  31. def sel_combo():
  32.     eleccion = combobox.get()
  33.     print(eleccion)
  34.  
  35.  
  36. ventana = tk.Tk()
  37. ventana.config(width=400, height=600)
  38. ventana.title("Mi primera app")
  39.  
  40. # Campos de formularios
  41. # campo nombre
  42. etiqueta = ttk.Label(text="Nombre")
  43. etiqueta.place(x=10, y=20)
  44. caja_nombre = ttk.Entry()
  45. caja_nombre.place(x=100, y=20, width=180, height=25)
  46.  
  47. # campo email
  48. etiqueta = ttk.Label(text="Email")
  49. etiqueta.place(x=10, y=70)
  50. caja_email = ttk.Entry()
  51. caja_email.place(x=100, y=70, width=180, height=25)
  52.  
  53. # campo telefono
  54. etiqueta = ttk.Label(text="TE")
  55. etiqueta.place(x=10, y=120)
  56. caja_tel = ttk.Entry()
  57. caja_tel.place(x=100, y=120, width=180, height=25)
  58.  
  59. boton = ttk.Button(text="Guardar", command=guardar)
  60. boton.place(x=120, y=180, width=120, height=50)
  61.  
  62. # listbox
  63. lista = tk.Listbox()
  64. lista.insert(0,"Python", "Java", "Prolog")
  65. lista.place(x=10, y=250)
  66. boton = ttk.Button(text="Elegir", command=sel_lista)
  67. boton.place(x=150, y=350)
  68.  
  69. # lista desplegable
  70. combobox = ttk.Combobox(state="readonly",values=[1,2,3,4,5,6])
  71. combobox.place(x=10,y=450)
  72. boton = ttk.Button(text="Elegir", command=sel_combo)
  73. boton.place(x=170, y=450)
  74.  
  75. # retornan ok
  76. salir = messagebox.askokcancel(title="Pregunta",message="¿Desea salir?")
  77.  
  78. # retornan siempre ok
  79. messagebox.showerror(title="Error", message="Estas equivocado")
  80.  
  81.  
  82. ventana.mainloop()
  83.  
Advertisement
Add Comment
Please, Sign In to add comment