Advertisement
teslariu

tkinter

Aug 27th, 2022
980
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.38 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # place
  5. import tkinter as tk
  6. from tkinter import ttk
  7. from tkinter import messagebox
  8.  
  9. def clic():
  10.     nombre = caja_nombre.get()
  11.     print(nombre)
  12.    
  13. def clic_lista():
  14.     seleccion = lista.get(lista.curselection())
  15.     print(seleccion)
  16.    
  17. def clic_combo():
  18.     seleccion = combobox.get()
  19.     print(seleccion)
  20.  
  21.  
  22.  
  23. ventana = tk.Tk()
  24. ventana.title("Mi primera app")
  25. ventana.config(width=400, height=600)
  26. # ventana.resizable(0,0) impide modificar el tamaño inicial
  27.  
  28. # boton con caja de texto
  29. caja_nombre = ttk.Entry()
  30. caja_nombre.place(x=70,y=40,width=200,height=25)
  31.  
  32. label = ttk.Label(text="Nombre")
  33. label.place(x=10, y=40)
  34.  
  35. boton = ttk.Button(text="Guardar", command=clic)
  36. boton.place(x=30, y=80)
  37.  
  38. # mostrar una imagen dentro de una etiqueta
  39. imagen = tk.PhotoImage(file="camion.png")
  40. label = ttk.Label(image=imagen)
  41. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  42.  
  43. # lista
  44. lista = tk.Listbox()
  45. lista.insert(0,"Python","C++","Java","Go")
  46. lista.place(x=10, y=120)
  47. boton = ttk.Button(text="Guardar", command=clic_lista)
  48. boton.place(x=10, y=300)
  49.  
  50. # lista desplegable (combobox)
  51. combobox = ttk.Combobox(
  52.                     state="readonly",
  53.                     values=[1,2,3,4,5,"Ana","Luis"]
  54.             )
  55. combobox.place(x=10,y=340)
  56. boton = ttk.Button(text="Guardar", command=clic_combo)
  57. boton.place(x=10, y=380)
  58.  
  59. # casilla de verificación
  60. estado = tk.BooleanVar()
  61. estado.set("False")
  62. casilla = ttk.Checkbutton(text="Acepto los términos y condiciones",variable=estado)
  63. casilla.place(x=10,y=420)
  64.  
  65. # barra de progreso
  66. barra = ttk.Progressbar(maximum=100)
  67. barra.place(x=10, y=450, width=200)
  68. barra.step(20)
  69. barra.start(10)
  70.  
  71. barra = ttk.Progressbar(maximum=100, orient=tk.VERTICAL)
  72. barra.place(x=300, y=300, height=200)
  73. barra.step(50)
  74. barra.start(10)
  75.  
  76. # cuadros de dialogo
  77. messagebox.showinfo(title="INFO", message="LO ESTOY ESPIANDO")
  78. messagebox.showwarning(title="Advertencia", message="Me estoy impacientando")
  79. messagebox.showerror(title="ERROR", message="¿Acaso no sabe sumar?")
  80.  
  81. # cuadros que retornan True o False
  82. decision = messagebox.askokcancel(title="Pregunta", message="¿Desea salir")
  83. decision = messagebox.askyesno(title="Pregunta", message="¿Desea salir")
  84. decision = messagebox.askretrycancel(title="Pregunta", message="¿Desea reintentar")
  85.  
  86.  
  87. ventana.mainloop()
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement