teslariu

place:m

Aug 26th, 2021
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. #  metodo place
  5.  
  6. import tkinter as tk
  7. from tkinter import ttk
  8.  
  9. ############
  10. def guardar_datos():
  11.     global datos
  12.     nombre = caja_nombre.get()
  13.     tel = caja_tel.get()
  14.     dato = {'nombre':nombre, 'tel':tel}
  15.     datos.append(dato)
  16.     print("\n",datos)
  17.     # borro las cajas
  18.     caja_nombre.delete(0, tk.END)
  19.     caja_tel.delete(0, tk.END)
  20.    
  21.    
  22. def listbox():
  23.     seleccion = lista.get(lista.curselection())
  24.     print(seleccion)
  25.    
  26. def desplegable():
  27.     seleccion = combo.get()
  28.     print(seleccion)
  29.    
  30.  
  31. ###################################
  32. datos = []  # creo una lista para almacenar los datos
  33.  
  34. ventana = tk.Tk()
  35.  
  36. ventana.title("Posicionamiento place")
  37. ventana.config(width=400, height=800)
  38.  
  39. # campo nombre
  40. etiqueta = ttk.Label(text="Nombre: ")
  41. etiqueta.place(x=160, y=120)
  42. caja_nombre = ttk.Entry()
  43. caja_nombre.place(x=220, y=120)
  44.  
  45. # campo tel
  46. etiqueta = ttk.Label(text="Teléfono: ")
  47. etiqueta.place(x=160, y=160)
  48. caja_tel = ttk.Entry()
  49. caja_tel.place(x=220, y=160)
  50.  
  51. # agrego un boton para guardar los datos
  52. boton = ttk.Button(text="Guardar", command=guardar_datos)
  53. boton.place(x=200, y=220, width=100, height=50)
  54.  
  55. # lista (listbox)
  56. lista = tk.Listbox()
  57. lista.insert(0,"Python", "C++", "Java")
  58. lista.place(x=10, y=100)
  59. boton = ttk.Button(text="Seleccionar", command=listbox)
  60. boton.place(x=10, y=270)
  61.  
  62. # imagen (dentro de una etiqueta)
  63. imagen = tk.PhotoImage(file="camion.png")
  64. label = ttk.Label(image=imagen)
  65. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.50)
  66.  
  67. # lista desplegable (combobox)
  68. combo = ttk.Combobox(state="readonly",values=["VB","Go","C#","Erlang"])
  69. combo.place(x=10, y=300)
  70. boton = ttk.Button(text="Seleccionar", command=desplegable)
  71. boton.place(x=10, y=330)
  72.  
  73. # casilla
  74. estado = tk.BooleanVar()
  75. estado.set("True")
  76. casilla = ttk.Checkbutton(text="Acepto las condiciones", variable=estado)
  77. casilla.place(x=10, y=380)
  78.  
  79. # barra de progreso
  80. barra = ttk.Progressbar(maximum=100)
  81. barra.place(x=10, y=450, width=200)
  82. barra.step(50)
  83. barra.start(100)
  84.  
  85. barra = ttk.Progressbar(orient=tk.VERTICAL)
  86. barra.place(x=300, y=450, height=200)
  87. barra.start(30)
  88.  
  89.  
  90.  
  91.  
  92.  
  93. ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment