teslariu

place

Jan 22nd, 2021
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 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 guardar_nombre():
  8.     nombre = caja.get()
  9.     print(f"Nombre '{nombre}' guardado")
  10.    
  11. def otro_saludo():
  12.     print("Otro botón presionado")
  13.    
  14. def listbox():
  15.     try:
  16.         seleccion = lista.get(lista.curselection())
  17.     except:
  18.         print("No ha seleccionado nada")
  19.     else:
  20.         print(f"Ha elegido {seleccion}")
  21.        
  22.    
  23. def combobox():
  24.     print(lista_desplegable.get())
  25.  
  26.  
  27.  
  28. ventana = tk.Tk()
  29. ventana.title("Posicionamiento place")
  30. ventana.config(width=400, height=800)
  31.  
  32.  
  33. # boton con ancho y alto
  34. boton = ttk.Button(text="Chau mundo", command=otro_saludo)
  35. boton.place(x=150, y=70, width=100, height=50)
  36.  
  37.  
  38. # etiquetas que almacena una imagen
  39. imagen = tk.PhotoImage(file="camion.png")
  40. etiqueta = ttk.Label(image=imagen)
  41. etiqueta.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  42.  
  43. # caja de texto
  44. caja = ttk.Entry()
  45. caja.place(x=10, y=40)
  46. caja.insert(0, "Inserte su nombre...")
  47.  
  48. # boton con ancho y alto por defecto (según el tamaño del texto)
  49. boton = ttk.Button(text="Guardar", command=guardar_nombre)
  50. boton.place(x=50, y=10)
  51.  
  52. # lista (listbox)
  53. lista = tk.Listbox()
  54. lista.insert(0, "Python", "C", "C++", "Java", "Perl")
  55. lista.place(x=10, y=100)
  56. boton = ttk.Button(text="Guardar selección", command=listbox)
  57. boton.place(x=10, y=270)
  58.  
  59. # lista desplegable (combobox):
  60. lista_desplegable =  ttk.Combobox(state="readonly",
  61.                                     values = [
  62.                                         "JavaScript",
  63.                                         "Erlang",
  64.                                         "Visual Basic"
  65.                                         ]
  66.                                 )
  67. lista_desplegable.place(x=10, y=300)
  68. boton = ttk.Button(text="Imprimir selección", command=combobox)
  69. boton.place(x=10,y=330)
  70.  
  71. # casilla de verificación:
  72. estado = tk.BooleanVar()
  73. estado.set("True")
  74. casilla = ttk.Checkbutton(text="Marcar por SI", variable=estado)
  75. casilla.place(x=10, y=380)
  76.  
  77.  
  78.  
  79.  
  80.  
  81. ventana.mainloop()
  82.  
Advertisement
Add Comment
Please, Sign In to add comment