Advertisement
teslariu

PLACE

Mar 10th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 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.  
  9.  
  10.  
  11. #################   Funciones  ##########################
  12.  
  13. def imprimir_saludo():
  14.     print("Botón presionado")
  15.  
  16. def imprimir_otro_saludo():
  17.     print("Otro botón presionado")
  18.    
  19. def guardar_nombre():
  20.     nombre = caja_de_texto.get()
  21.     if nombre:
  22.         print(f"Nombre '{nombre}' guardado")
  23.        
  24. def imprimir_listbox():
  25.     eleccion = lista.curselection()
  26.     print(lista.get(eleccion))
  27.        
  28. def imprimir_combobox():
  29.     print(lista_combobox.get())
  30.  
  31. #####################     main  #############################
  32.  
  33.  
  34. ventana = tk.Tk()
  35. ventana.title("Posicionamiento place")
  36. ventana.config(width=400, height=800)
  37.  
  38. # un boton con alto y ancho según texto
  39. boton = ttk.Button(text="Presionar", command=imprimir_saludo)
  40. boton.place(x=150, y=10)
  41.  
  42. # otra forma de llamar a un boton con medidas propias
  43. boton = ttk.Button(command=imprimir_otro_saludo)
  44. boton.config(text="Soy otro botón")
  45. boton.place(x=150, y=70, width=100, height=50)
  46.  
  47. # etiquetas estáticas
  48. etiqueta = ttk.Label(text="Guarde los datos")
  49. etiqueta.place(x=160, y=120)
  50.  
  51. # imagen (dentro de una etiqueta)
  52. imagen = tk.PhotoImage(file="camion.png")
  53. label = ttk.Label(image=imagen)
  54. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  55.  
  56.  
  57. ########### boton con caja de texto y etiqueta #################3
  58. caja_de_texto = ttk.Entry()
  59. caja_de_texto.place(x=10,y=70)
  60. # agrego un texto por defecto en la caja
  61. caja_de_texto.insert(0, "Ej: Alejandro Luis")
  62. # borro 'Ej: '
  63. caja_de_texto.delete(0,4)
  64. # borro todos los textos
  65. # caja_de_texto.delete(0, tk.END)
  66.  
  67.  
  68. etiqueta = ttk.Label(text="Ingrese su nombre")
  69. etiqueta.place(x=20, y=50)
  70.  
  71. # mi forma preferida de usar un botón
  72. boton = ttk.Button(text="Guardar el nombre", command=guardar_nombre)
  73. boton.place(x=20, y=110, width=120, height=35)
  74.  
  75.  
  76.  
  77. ###################  LISTAS (LISTBOX) ########################
  78. lista = tk.Listbox()
  79. lista.insert(0, "Python", "C", "C++", "Java", "Erlang")
  80. lista.place(x=10, y=150)
  81. boton = ttk.Button(text="Imprimir", command=imprimir_listbox)
  82. boton.place(x=10, y=320)
  83.  
  84.  
  85. ###################  LISTAS DESPLEGABLES (COMBOBOX) ########################
  86. lista_combobox = ttk.Combobox(
  87.             state="readonly",
  88.             values = [
  89.                 "Visual Basic",
  90.                 "JavaScript",
  91.                 "Go",
  92.                 "R",
  93.                 "Rust"
  94.                 ]
  95.             )
  96. lista_combobox.place(x=10, y=380)
  97. boton = ttk.Button(text="Imprimir selección", command=imprimir_combobox)
  98. boton.place(x=10, y=420)
  99.  
  100. #################  CASILLA DE VERIFICACION   ################
  101. estado = tk.BooleanVar()  # declaro una variable booleana
  102. estado.set("False")       # inicializo la variable
  103. casilla = ttk.Checkbutton(text="Opcion", variable=estado)
  104. casilla.place(x=10, y=480)
  105.  
  106.  
  107.  
  108.  
  109. ventana.mainloop()
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement