teslariu

tkinter

Oct 11th, 2022
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.32 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 guardar_nombre():
  9.     data = nombre.get()
  10.     print(data)
  11.    
  12. def elegir():
  13.     nombre = lista.get(lista.curselection())
  14.     print(nombre)
  15.    
  16. def seleccion():
  17.     print(combo.get())
  18.  
  19.  
  20. ventana = tk.Tk()
  21. ventana.title("Mi primera app")
  22. ventana.config(width=400, height=800)
  23. # ventana.resizable(0,0)
  24.  
  25. # boton
  26. boton = ttk.Button(text="Guardar nombre",command=guardar_nombre)
  27. boton.place(x=50, y=10, width=120, height=50)
  28.  
  29. # campo nombre
  30. etiqueta = ttk.Label(text="Nombre")
  31. etiqueta.place(x=200, y=10)
  32. nombre = ttk.Entry()
  33. nombre.place(x=250, y=10)
  34.  
  35. # lista (listbox)
  36. lista = tk.Listbox()
  37. lista.insert(0, "Juan","Ana","Oscar","Rodrigo")
  38. lista.place(x=10, y=100)
  39. boton = ttk.Button(text="Elegir nombre",command=elegir)
  40. boton.place(x=20, y=270, width=100, height=30)
  41.  
  42. # lista desplegable
  43. combo = ttk.Combobox(
  44.                 state="readonly",
  45.                 values=["C++","Python","Java","Go","Ruby"]
  46.         )
  47. combo.place(x=20, y=320)
  48. boton = ttk.Button(text="Seleccionar",command=seleccion)
  49. boton.place(x=20, y=380)
  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.50)
  55.  
  56. # casilla de verificacion
  57. estado = tk.BooleanVar()
  58. estado.set("False")
  59. casilla = ttk.Checkbutton(text="Aceptar términos y condiciones", variable=estado)
  60. casilla.place(x=170, y=100)
  61.  
  62. # barra de progreso
  63. barra = ttk.Progressbar(maximum=100)
  64. barra.place(x=10, y=450, width=200)
  65. barra.step(20)
  66. barra.start(5)
  67.  
  68. barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
  69. barra.place(x=300, y=450, height=200)
  70. barra.step(40)
  71. barra.start(5)
  72.  
  73. ############# cuadros de dialogo #######################
  74. # de info
  75. mb.showinfo(title="INFO", message="HA PASADO muucho tiempo...")
  76. mb.showwarning(title="advertencia", message="Ojo con el piojo...")
  77. mb.showerror(title="ERROR", message="Has errado...")
  78.  
  79. # condicionales
  80. resp1 = mb.askokcancel(title="Pregunta", message="¿Desea continuar")
  81. resp2 = mb.askyesno(title="Confirmación", message="¿Desea guardar los datos?")
  82. resp3 = mb.askretrycancel(title="Pregunta", message="¿Reintenta nuevamente")
  83.  
  84. ventana.mainloop()
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
Add Comment
Please, Sign In to add comment