teslariu

place tkinter

Jun 6th, 2023
1,186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # place
  5.  
  6. import tkinter as tk
  7. from tkinter import ttk
  8. from tkinter import messagebox
  9. from pprint import pprint
  10.  
  11.  
  12. main = tk.Tk()
  13. main.title("Mi primera app")
  14. main.config(width=400, height=800)
  15.  
  16. datos = []
  17.  
  18. def guardar_nombre():
  19.    
  20.     global datos
  21.     nombre = caja_nombre.get()
  22.     tel = caja_tel.get()
  23.     dato = {"nombre": nombre, "telefono":tel}
  24.     datos.append(dato)
  25.     print()
  26.     pprint(datos)
  27.    
  28.     # muestro un mensaje
  29.     messagebox.showinfo(title="INFO", message="Datos guardados correctamente")
  30.    
  31.     # borro los campos del formulario
  32.     caja_nombre.delete(0, tk.END)
  33.     caja_tel.delete(0, tk.END)
  34.    
  35. def guardar_lista():
  36.     print(lista.get(lista.curselection()))
  37.  
  38.  
  39. def guardar_combo():
  40.     valor = combo.get()
  41.     print(valor)
  42.  
  43. # para evitar redimensionamiento
  44. # main.resizable(0,0)
  45.  
  46. # Campos de datos de un formulario
  47. # campo nombre
  48. caja_nombre = ttk.Entry()
  49. caja_nombre.place(x=90, y=10, width=150, height=25)
  50. etiqueta = ttk.Label(text="Nombre")
  51. etiqueta.place(x=10, y=10)
  52.  
  53. # campo TE
  54. caja_tel = ttk.Entry()
  55. caja_tel.place(x=90, y=60, width=150, height=25)
  56. etiqueta = ttk.Label(text="TEL")
  57. etiqueta.place(x=10, y=60)
  58.  
  59. boton = ttk.Button(text="Guardar datos", command=guardar_nombre)
  60. boton.place(x=60, y=100, width=120, height=50)
  61.  
  62. # lista (listbox)
  63. lista = tk.Listbox()
  64. lista.insert(0, "Python", "C", "Java")
  65. lista.place(x=10, y=150)
  66. boton = ttk.Button(text="Guardar", command=guardar_lista)
  67. boton.place(x=10, y=330)
  68.  
  69. # imagen dentro de una etiqueta
  70. imagen = tk.PhotoImage(file="camion2.png")
  71. et = ttk.Label(image=imagen)
  72. et.place(relx=0.50, rely=0.5, relwidth=0.5, relheight=0.5)
  73.  
  74. # lista desplegable (combobox)
  75. combo = ttk.Combobox(state='readonly',
  76.                     values = [1,2,30,400,5000,"infinito"]
  77.                 )
  78. combo.place(x=10, y=360)
  79. boton = ttk.Button(text="Guardar", command=guardar_combo)
  80. boton.place(x=10, y=390)
  81.  
  82. # casilla de verificación
  83. estado = tk.BooleanVar()
  84. estado.set("True")
  85. casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=estado)
  86. casilla.place(x=100, y=390)
  87.  
  88. # barra de progreso
  89. barra = ttk.Progressbar(maximum=100)
  90. barra.place(x=10, y=550, width=200)
  91. barra.step(20)
  92. barra.start(10)
  93.  
  94. barraV = ttk.Progressbar(orient=tk.VERTICAL, maximum=100)
  95. barraV.place(x=300, y=550, height=200)
  96. barraV.step(20)
  97. barraV.start(10)
  98.  
  99. main.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment