Advertisement
teslariu

metodo_place

Apr 24th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Posicionamiento PLACE"""
  5. import tkinter as tk
  6. from tkinter import ttk
  7.  
  8. datos = [] # datos = [dato1, dato2,]
  9.  
  10.  
  11. def guardar():
  12.     dato = {}  # dato = {"nombre":nom, "email":mail, "tel":tel}
  13.     nom = nombre.get()
  14.     if nom:
  15.         print(f"Nombre {nom} guardado")
  16.         dato["nombre"] = nom
  17.     else:
  18.         print("No se ha ingresado ningún nombre")
  19.    
  20.     mail = email.get()
  21.     if mail and "@" in mail:
  22.         print(f"Email {mail} guardado")
  23.         dato["email"] = mail
  24.     else:
  25.         print("No se ha ingresado ningún email")
  26.    
  27.     tel = telefono.get()
  28.     if tel:
  29.         print(f"Telefono {tel} guardado")
  30.         dato["tel"] = tel
  31.     else:
  32.         print("No se ha ingresado ningún telefono")
  33.        
  34.     if nom and mail and tel:
  35.         datos.append(dato)
  36.         print("Datos de usuario almacenados")
  37.        
  38.        
  39. def mostrar_lista():
  40.     seleccion = lista.get(lista.curselection())
  41.     print(seleccion)
  42.    
  43. def mostrar_combo():
  44.     seleccion = combo.get()
  45.     print(seleccion)
  46.        
  47.  
  48. ventana = tk.Tk()
  49. ventana.title("PLACE")
  50. ventana.config(width=400, height=800)
  51.  
  52. ############## Formulario de inscripción ################
  53.  
  54. ##### campo nombre  ################
  55. nombre = ttk.Entry()
  56. nombre.insert(0,"Ej: Juan")
  57. nombre.place(x=10, y=10, width=200, height=25)
  58. etiqueta = ttk.Label(text="Nombre")
  59. etiqueta.place(x=220, y=10)
  60.  
  61. ##### campo email  ################
  62. email = ttk.Entry()
  63. email.place(x=10, y=50, width=200, height=25)
  64. etiqueta = ttk.Label(text="email")
  65. etiqueta.place(x=220, y=50)
  66.  
  67. ##### campo telefono  ################
  68. telefono = ttk.Entry()
  69. telefono.place(x=10, y=90, width=200, height=25)
  70. etiqueta = ttk.Label(text="telefono")
  71. etiqueta.place(x=220, y=90)
  72.  
  73. # boton
  74. boton = ttk.Button(text="Guardar", command=guardar)
  75. boton.place(x=50, y=130)
  76.  
  77.  
  78. #### listas
  79. lista = tk.Listbox()
  80. lista.insert(0,"Python", "C++", "Java", "C#")
  81. lista.place(x=10, y=160)
  82. boton = ttk.Button(text="Lista", command=mostrar_lista)
  83. boton.place(x=50, y=340)
  84.  
  85. ### imagen dentro de una etiqueta
  86. imagen = tk.PhotoImage(file="camion.png")
  87. label = ttk.Label(image=imagen)
  88. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  89.  
  90. ##### lista desplegable
  91. combo = ttk.Combobox(state="readonly",
  92.                                 values=["C","C++","Erlang","Ruby","R"]
  93.                                 )
  94. combo.place(x=10, y=400)
  95. boton = ttk.Button(text="Lista", command=mostrar_combo)
  96. boton.place(x=50, y=430)
  97.  
  98. ##### casilla de verificacion
  99. valor_casilla = tk.BooleanVar()
  100. casilla = ttk.Checkbutton(text="Acepta las condiciones", variable=valor_casilla)
  101. valor_casilla.set("True")
  102. casilla.place(x=50, y=480)
  103.  
  104.  
  105.  
  106.  
  107. ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement