teslariu

tkinter place

Jun 9th, 2023
1,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.77 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. from tkinter import messagebox
  7. from pprint import pprint
  8.  
  9.  
  10. contactos = []
  11.  
  12. def formulario():
  13.     global contactos
  14.     nombre = caja_nombre.get()
  15.     tel = caja_tel.get()
  16.    
  17.     # chequeo si faltan datos
  18.     if not len(nombre) or not len(tel):
  19.         messagebox.showwarning(title='Advertencia', message='Formulario incompleto')
  20.         return
  21.        
  22.    
  23.     contacto = {"nombre":nombre, "telefono":tel}
  24.     contactos.append(contacto)
  25.     print()
  26.     pprint(contactos)
  27.    
  28.     # borro el formulario
  29.     caja_nombre.delete(0, tk.END)
  30.     caja_tel.delete(0, tk.END)
  31.    
  32.     # muestro un mensaje de datos guardados
  33.     messagebox.showinfo(title='Mensaje', message='Datos guardados')
  34.  
  35. def ver_lista():
  36.     valor = lista.get(lista.curselection())
  37.     print(valor)
  38.  
  39. def ver_combo():
  40.     print(combo.get())
  41.  
  42.  
  43.  
  44. root = tk.Tk()
  45. root.title("Posicionamiento place")
  46. root.config(width=400, height=800)
  47.  
  48. # Campo nombre
  49. caja_nombre = ttk.Entry()
  50. caja_nombre.place(x=120, y=10, width=150, height=25)
  51. etiqueta = ttk.Label(text='Nombre')
  52. etiqueta.place(x=20, y=10)
  53.  
  54.  
  55. # Campo telefono
  56. caja_tel = ttk.Entry()
  57. caja_tel.place(x=120, y=60, width=150, height=25)
  58. etiqueta = ttk.Label(text='Teléfono')
  59. etiqueta.place(x=20, y=60)
  60.  
  61. # boton
  62. boton = ttk.Button(text="Guardar", command=formulario)
  63. boton.place(x=130, y=100, height=50, width=100)
  64.  
  65.  
  66. ############## Widgets sueltos
  67. # lista estatica (listbox)
  68. lista = tk.Listbox()
  69. lista.insert(0,"Python","C++","Java","Go")
  70. lista.place(x=10, y=200)
  71. boton = ttk.Button(text="Guardar", command=ver_lista)
  72. boton.place(x=20, y=370)
  73.  
  74. # lista desplegable (combobox)
  75. combo = ttk.Combobox(state="readonly", values=[1,2,45,67,778,'infinito'])
  76. combo.place(x=10, y=400)
  77. boton = ttk.Button(text="Guardar", command=ver_combo)
  78. boton.place(x=20, y=430)
  79.  
  80. # imagen de fondo
  81. imagen = tk.PhotoImage(file='camion2.png')
  82. label = ttk.Label(image=imagen)
  83. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  84.  
  85. # casilla de verificacion
  86. estado = tk.BooleanVar()
  87. estado.set("False")
  88. casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=estado)
  89. casilla.place(x=20, y=460)
  90.  
  91. # barra de progreso
  92. barra = ttk.Progressbar(maximum=100)
  93. barra.place(x=10, y=500, width=200)
  94. barra.step(99.9)
  95. barra.start(10)
  96.  
  97. barra = ttk.Progressbar(orient=tk.VERTICAL, maximum=100)
  98. barra.place(x=300, y=500, height=200)
  99. barra.step(30)
  100. barra.start(30)
  101.  
  102. # mas cuadros de mensaje : estos retornan true or false
  103. messagebox.askokcancel(title='Pregunta', message='¿Desea cancelar?')
  104. messagebox.askyesno(title='Mensaje', message='¿Desea salir?')
  105. messagebox.askretrycancel(title='Duda existencial', message='Probar nuevamente')
  106.  
  107. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment