teslariu

tkinter

Jan 26th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # place
  5. import tkinter as tk
  6. from pprint import pprint
  7. from tkinter import ttk
  8. from tkinter import messagebox
  9.  
  10.  
  11. def saludar():
  12.     global nombres
  13.     nombres.append(caja.get())
  14.     pprint(nombres)
  15.     caja.delete(0, tk.END)
  16.  
  17. def op_lista():
  18.     opcion = lista.get(lista.curselection())
  19.     print(opcion)
  20.  
  21. def op_combo():
  22.     opcion = combo.get()
  23.     print(opcion)
  24.  
  25. nombres = []
  26.  
  27.  
  28. ventana = tk.Tk()
  29. ventana.title("Ventana con place")
  30. ventana.config(width=400, height=800)
  31.  
  32. boton = ttk.Button(text="Guardar nombre", command=saludar)
  33. boton.place(x=30, y=10, width=100, height=40)
  34.  
  35. etiqueta = ttk.Label(text="Nombre:")
  36. etiqueta.place(x=150, y=20)
  37.  
  38. caja = ttk.Entry()
  39. caja.place(x=200, y=20, width=150, height=25)
  40.  
  41.  
  42. # lista (listbox)
  43. lista = tk.Listbox()
  44. lista.insert(0,"Python","C","Java","Go")
  45. lista.place(x=10, y=100)
  46. boton = ttk.Button(text="Guardar elección", command=op_lista)
  47. boton.place(x=10, y=270)
  48.  
  49. # lista desplegable (combobox)
  50. combo = ttk.Combobox(state="readonly", values=[1,20,50,145,1000])
  51. combo.place(x=10,y=300)
  52. boton = ttk.Button(text="Guardar elección", command=op_combo)
  53. boton.place(x=10, y=330)
  54.  
  55. # imagen dentro de una etiqueta
  56. imagen = tk.PhotoImage(file="camion2.png")
  57.  
  58. label = ttk.Label(image=imagen)
  59. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  60.  
  61. # casilla de verificación
  62. estado = tk.BooleanVar()
  63. estado.set("False")
  64. casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=estado)
  65. casilla.place(x=10, y=380)
  66.  
  67.  
  68. # barra de progreso
  69. barra = ttk.Progressbar(maximum=100)
  70. barra.place(x=10, y=450, width=200)
  71. barra.step(50)
  72. barra.start(20)
  73.  
  74. # barra vertical
  75. barra = ttk.Progressbar(orient=tk.VERTICAL, maximum=100)
  76. barra.place(x=300, y=450, height=200)
  77. barra.step(50)
  78. barra.start(20)
  79.  
  80. ###### cuadros de dialogo
  81.  
  82. # devuelven True or False
  83. messagebox.askokcancel(title="Pregunta", message="¿Desea seguir?")
  84. messagebox.askyesno(title="Pregunta", message="¿Seguro desea seguir?")
  85. messagebox.askretrycancel(title="Pregunta", message="¿Desea reintentar?")
  86.  
  87.  
  88. # devuelven ok
  89. messagebox.showinfo(title="Info", message="Se ha guardado el registro")
  90. messagebox.showwarning(title="Advertencia", message="Ojo, no se equivoque")
  91. messagebox.showerror(title="Error", message="Está en el horno...")
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. ventana.mainloop()
  101.  
Add Comment
Please, Sign In to add comment