teslariu

tkinter_place

Sep 15th, 2023
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 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. from tkinter import messagebox as mb
  7.  
  8. def saludar():
  9.     print("Hola")
  10.    
  11. def elegir_lista():
  12.     posicion = lista.curselection()
  13.     try:
  14.         valor = lista.get(posicion)
  15.     except Exception:
  16.         pass
  17.     else:  
  18.         if valor:
  19.             print(valor)
  20.  
  21.  
  22. def elegir_combo():
  23.     try:
  24.         valor = combo.get()
  25.     except Exception:
  26.         pass
  27.     else:  
  28.         if valor:
  29.             print(valor)
  30.  
  31.  
  32.  
  33. ventana = tk.Tk()
  34. ventana.title("Posicionamiento place")
  35. ventana.config(width=400, height=800)
  36.  
  37. boton = ttk.Button(text="Presione aquí", command=saludar)
  38. boton.place(x=50, y=10)
  39.  
  40.  
  41. # lista (listbox)
  42. lista = tk.Listbox()
  43. lista.insert(0, "Python", "Java", "HTML", "Go")
  44. lista.place(x=10, y=100)
  45. boton = ttk.Button(text="Seleccionar", command=elegir_lista)
  46. boton.place(x=10, y=270)
  47.  
  48. # lista desplegable (combobox)
  49. combo = ttk.Combobox(state='readonly',
  50.                     values = ["Ale", "Ana", "Juana", "Victor"],
  51.                     )
  52. combo.place(x=10, y=300)
  53. boton = ttk.Button(text="Seleccionar", command=elegir_combo)
  54. boton.place(x=10, y=330)
  55.  
  56. # imagen dentro de una etiqueta
  57. imagen = tk.PhotoImage(file="camion.png")
  58. label = ttk.Label(image=imagen)
  59. label.place(relx=0.5, rely=0.5, relwidth=0.4, relheight=0.40)
  60.  
  61. # casilla de verificación
  62. aceptar = tk.BooleanVar()
  63. aceptar.set("False")
  64. casilla = ttk.Checkbutton(text="Aceptar Términos y condiciones", variable=aceptar)
  65. casilla.place(x=10, y=380)
  66.  
  67. # barra de progreso
  68. barra = ttk.Progressbar(maximum=100)
  69. barra.step(50)
  70. barra.start(20)
  71. barra.place(x=10, y=450, width=200)
  72.  
  73. barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
  74. barra.step(75)
  75. barra.start(20)
  76. barra.place(x=300, y=450, height=200)
  77.  
  78. # paneles y pestañas
  79. panel = ttk.Notebook()
  80. panel.place(x=180, y=50)
  81.  
  82. pestania1= ttk.Label(panel,text="Aula virtual")
  83. pestania2= ttk.Label(panel,text="Buscador de Internet")
  84.  
  85. panel.add(pestania1, text="Alumni", padding=20)
  86. panel.add(pestania2, text="Google", padding=20)
  87.  
  88.  
  89.  
  90.  
  91. # cuadros de dialogo
  92. # retornan True
  93. mb.showinfo(title="Info",message="Info del sistema")
  94. mb.showwarning(title="Advertencia",message="Ojo con la info del sistema")
  95. mb.showerror(title="Error",message="ERROR de sistema")
  96.  
  97. # retornan True or False
  98. mb.askokcancel(title="Advertencia",message="¿desea ejecutar el programa?")
  99. mb.askyesno(title="Advertencia",message="¿Desea salir del sistema?")
  100. mb.askretrycancel(title="Advertencia",message="Intente nuevamente")
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. ventana.mainloop()
  112.  
Add Comment
Please, Sign In to add comment