teslariu

place

Feb 13th, 2021
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 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("Boton presionado")
  9.    
  10. def guardar_nombre():
  11.     nom = nombre.get()
  12.     print(nom)
  13.    
  14. def guardar_listbox():
  15.     seleccion = lista.get(lista.curselection())
  16.     print(seleccion)
  17.  
  18. def guardar_combobox():
  19.     seleccion = combobox.get()
  20.     print(seleccion)
  21.  
  22.  
  23. ###################################################################
  24.  
  25. ventana = tk.Tk()
  26. ventana.title("Posicionamiento place")
  27. ventana.config(width=400, height=800)
  28.  
  29. # botones
  30. boton = ttk.Button(text="Hola mundo", command=imprimir_saludo)
  31. boton.place(x=50, y=10, width=100, height=50)
  32.  
  33.  
  34.  
  35. # etiquetas
  36. label = ttk.Label(text="Hola mundo")
  37. label.place(x=160, y=120)
  38.  
  39. # imagen (adentro de una etiqueta)
  40. imagen = tk.PhotoImage(file="camion.png")
  41. label = ttk.Label(image=imagen)
  42. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  43.  
  44. # caja de texto
  45. nombre = ttk.Entry()
  46. nombre.place(x=10, y=70)
  47. boton = ttk.Button(command=guardar_nombre)
  48. boton.place(x=150, y=70, width=100, height=50)
  49. boton.config(text="Guardar nombre")
  50.  
  51. # lista estática (listbox)
  52. lista = tk.Listbox()
  53. lista.insert(0,"Python", "C", "C++", "Java")
  54. lista.place(x=10, y=100)
  55. boton = ttk.Button(text="Guardar selección", command=guardar_listbox)
  56. boton.place(x=10, y=270)
  57.  
  58. # lista desplegable (combobox)
  59. combobox = ttk.Combobox(state="readonly",
  60.                         values=[
  61.                             "Visual Basic",
  62.                             "Python",
  63.                             "Erlang",
  64.                             "Rust",
  65.                             "Prolog"
  66.                             ]
  67.                         )
  68. combobox.place(x=10, y=300)
  69. boton = ttk.Button(text="Imprimir selección", command=guardar_combobox)
  70. boton.place(x=10, y=330)
  71.  
  72. # casilla de verificacion
  73. estado = tk.BooleanVar()
  74. estado.set("True")
  75. checkbutton = ttk.Checkbutton(text="Aceptar las condiciones",variable=estado)
  76. checkbutton.place(x=10, y=380)
  77.  
  78.  
  79. ventana.mainloop()
  80.  
Advertisement
Add Comment
Please, Sign In to add comment