Advertisement
teslariu

tkinter place

Sep 21st, 2022
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # place.py
  5.  
  6. import tkinter as tk
  7. from tkinter import ttk
  8. from tkinter import messagebox
  9.  
  10. def clic():
  11.     nombre = caja_nombre.get()
  12.     print(nombre)
  13.    
  14. def clic_listbox():
  15.     seleccion = lista.get(lista.curselection())
  16.     print(seleccion)
  17.    
  18. def clic_combo():
  19.     nombre = combo.get()
  20.     print(nombre)
  21.  
  22.  
  23. ventana = tk.Tk()
  24. ventana.title("Place")
  25. ventana.config(width=400, height=600)
  26. ventana.resizable(True,True)
  27. ventana.minsize(300,300)
  28.  
  29. # Etiqueta
  30. etiqueta = ttk.Label(text="Nombre")
  31. etiqueta.place(x=10, y=10)
  32.  
  33. # caja de texto
  34. caja_nombre = ttk.Entry()
  35. caja_nombre.place(x=80, y=10, width=150, height=25)
  36.  
  37. # Boton
  38. boton = ttk.Button(text="Guardar", command = clic)
  39. boton.place(x=120, y= 50, width=70, height=35)
  40.  
  41. # etiqueta con una imgen
  42. imagen = tk.PhotoImage(file="camion.png")
  43. etiqueta = ttk.Label(image=imagen)
  44. etiqueta.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  45.  
  46. # Listbox
  47. lista = tk.Listbox()
  48. lista.insert(0, "Python", "C++", "Java", "Erlang")
  49. lista.place(x=10, y=150)
  50.  
  51. boton = ttk.Button(text="Guardar", command = clic_listbox)
  52. boton.place(x=10, y= 350, width=70, height=35)
  53.  
  54.  
  55. # Combobox
  56. combo = ttk.Combobox(
  57.         state="readonly",
  58.         values = ["Andrea", "Juana", "Emilio"]
  59.         )
  60. combo.place(x=10, y=450)
  61.  
  62. boton = ttk.Button(text="Guardar", command = clic_combo)
  63. boton.place(x=10, y= 480, width=70, height=35)
  64.  
  65. # casilla de verificación
  66. estado = tk.BooleanVar()
  67. estado.set("False")
  68. casilla = ttk.Checkbutton(text="Acepto los términos y condiciones", variable=estado)
  69. casilla.place(x=150, y=200)
  70.  
  71. # barra de progreso
  72. barra = ttk.Progressbar(maximum=100)
  73. barra.place(x=10, y=550, width=300)
  74. barra.step(10)
  75. barra.start(3)
  76.  
  77. barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
  78. barra.place(x=300, y=220, height=300)
  79. barra.step(50)
  80. barra.start(60)
  81.  
  82. #### cuadros de dialogo
  83.  
  84. # siempre retornan la cadena "ok"
  85. messagebox.showinfo(title="Información", message="Has sido despedido")
  86. messagebox.showwarning(title="Advertencia", message="Si no saluda lo despido")
  87. messagebox.showerror(title="Error", message="Te has equivocado")
  88.  
  89. # retornan True or False
  90. respuesta = messagebox.askokcancel(title="Pregunta", message="¿Desea salir")
  91. if respuesta:
  92.     print("Adios...")
  93. else:
  94.     print("Sigamos entonces...")
  95.    
  96. respuesta = messagebox.askyesno(title="Requisito", message="¿Es mayor de edad?")
  97. if respuesta:
  98.     print("Puede beber")
  99. else:
  100.     print("Prohibido beber...")
  101.    
  102. respuesta = messagebox.askretrycancel(title="Pregunta", message="¿Desea reintentar")
  103. if respuesta:
  104.     print("Probemos de nuevo...")
  105. else:
  106.     print("Bueno, la proxima vez será...")
  107.    
  108.    
  109. ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement