teslariu

code

Aug 14th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.49 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import tkinter as tk
  5. from tkinter import ttk
  6.  
  7. def imprimir_saludo():
  8.     print("HOLA")
  9.    
  10. def guardar_datos():
  11.     global personas
  12.     nombre = caja_nombre.get()
  13.     email = caja_email.get()
  14.     nac = caja_nac.get()
  15.     direcc = caja_direc.get()
  16.     tel = caja_tel.get()
  17.     persona = {"nombre":nombre,
  18.                 "email": email,
  19.                 "nacionalidad": nac,
  20.                 "direccion":direcc,
  21.                 "telefono":tel}
  22.     personas.append(persona)
  23.    
  24.     print("Datos guardados")
  25.     for persona in personas:
  26.         print(persona)
  27.        
  28.     # una vez impreso, borro todas las cajas
  29.     caja_direc.delete(0,tk.END)
  30.     caja_email.delete(0,tk.END)
  31.     caja_nac.delete(0,tk.END)
  32.     caja_nombre.delete(0,tk.END)
  33.     caja_tel.delete(0,tk.END)
  34.    
  35.  
  36. def guardar_lista():
  37.     seleccion = lista.get(lista.curselection())
  38.     print(seleccion)
  39.  
  40. def guardar_combo():
  41.     seleccion = combo.get()
  42.     print(seleccion)    
  43.    
  44.  
  45. # lista que almacena los datos
  46. personas = []
  47.  
  48. ###################  ventana  #######################################
  49.  
  50.  
  51. ventana = tk.Tk()
  52.  
  53. ventana.title("FORMULARIO DE INSCRIPCION")
  54. ventana.config(width=400, height=800)
  55. # ventana.resizable(0,0) impide redimensionar la ventana
  56.  
  57. ##### formulario de ingreso de datos ############
  58.  
  59. # campo nombre
  60. caja_nombre = ttk.Entry()
  61. caja_nombre.place(x=150, y=40)
  62. etiqueta = tk.Label(text="Nombre")
  63. etiqueta.place(x=40, y=40)
  64.  
  65. # campo email
  66. caja_email = ttk.Entry()
  67. caja_email.place(x=150, y=70)
  68. etiqueta = tk.Label(text="email")
  69. etiqueta.place(x=40, y=70)
  70.  
  71. # campo nacionalidad
  72. caja_nac = ttk.Entry()
  73. caja_nac.place(x=150, y=100)
  74. etiqueta = tk.Label(text="Nacionalidad")
  75. etiqueta.place(x=40, y=100)
  76.  
  77. # campo telefono
  78. caja_tel = ttk.Entry()
  79. caja_tel.place(x=150, y=130)
  80. etiqueta = tk.Label(text="Telefono")
  81. etiqueta.place(x=40, y=130)
  82.  
  83. # campo direccion
  84. caja_direc = ttk.Entry()
  85. caja_direc.place(x=150, y=160)
  86. etiqueta = tk.Label(text="Direccion")
  87. etiqueta.place(x=40, y=160)
  88.  
  89.  
  90. # boton con ancho y alto según el tamaño del texto
  91. # boton = ttk.Button(text="ENTER", command=imprimir_saludo)
  92. # boton.place(x=50, y=10)
  93.  
  94. # boton con ancho y alto
  95. boton = ttk.Button(text="GUARDAR", command=guardar_datos)
  96. boton.place(x=120, y=200, width=100, height=30)
  97.  
  98. # imagenes dentro de etiquetas
  99. imagen = tk.PhotoImage(file="camion.png")
  100. label = ttk.Label(image=imagen)
  101. label.place(relx=0.5, rely=0.50, relwidth=0.5, relheight=0.5)
  102.  
  103. # lista
  104. lista = tk.Listbox()
  105. lista.insert(0,"Python","Ruby","Erlang","GO")
  106. lista.place(x=10, y=270)
  107. boton = ttk.Button(text="Seleccionar", command=guardar_lista)
  108. boton.place(x=10, y=450)
  109.  
  110. # lista desplegable
  111. combo = ttk.Combobox(state="readonly",
  112.                 values=["Rojo","Azul","Blanco","Marron","Negro"]
  113.                 )
  114. combo.place(x=10, y=480)
  115. boton = ttk.Button(text="Seleccionar", command=guardar_combo)
  116. boton.place(x=10, y=520)
  117.  
  118.  
  119. # casilla de verificación
  120. estado_casilla = tk.BooleanVar()
  121. estado_casilla.set("True")
  122. casilla = ttk.Checkbutton(text="ACEPTAR CONDICIONES", variable=estado_casilla)
  123. casilla.place(x=10, y=580)
  124.  
  125. # barra de progreso horizontal
  126. barra = ttk.Progressbar(maximum=200)
  127. barra.place(x=10, y=650, width=200)
  128. barra.step(99.9)
  129. barra.start()
  130.  
  131. # barra de progreso vertical
  132. barra = ttk.Progressbar(orient=tk.VERTICAL, maximum=100)
  133. barra.place(x=280, y=600, height=200)
  134. barra.step(99.9) # asegura que la barra llegue al final
  135. barra.start(20)
  136.  
  137.  
  138.  
  139. ventana.mainloop()
  140.  
Add Comment
Please, Sign In to add comment