Advertisement
teslariu

tkinter place

Nov 4th, 2023
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # PLACE
  5.  
  6. import tkinter as tk
  7. from tkinter import ttk
  8. from tkinter import messagebox
  9.  
  10. def guardar():
  11.     from pprint import pprint
  12.     global personas
  13.     nombre = caja_nombre.get()
  14.     if not nombre or nombre.isspace():
  15.         messagebox.showerror(title="Advertencia", message="Nombre inválido")
  16.         return
  17.    
  18.     email = caja_email.get()
  19.     persona = {"nombre": nombre, "email":email}
  20.     personas.append(persona)
  21.     pprint(personas)
  22.     caja_email.delete(0,tk.END)
  23.     caja_nombre.delete(0,tk.END)
  24.    
  25. def guardar_lista():
  26.     cursor = lista.curselection()
  27.     curso = lista.get(cursor)
  28.     print(curso)
  29.    
  30. def guardar_combo():
  31.     valor = combobox.get()
  32.     print(valor)
  33.    
  34.    
  35.  
  36. # personas = [{"nombre":"Ale", "email":"ale@ale.com"}, {}, ...]
  37.  
  38. personas = []
  39.  
  40.  
  41.  
  42.  
  43. ######## parte grafica  #################
  44.  
  45. ventana = tk.Tk()
  46. ventana.title("Mi app")
  47. # ventana.resizable(False,False)
  48. ventana.config(width=400, height=800)
  49.  
  50. # campos de datos
  51.  
  52. # campo nombre
  53. etiqueta = tk.Label(text="Nombre")
  54. etiqueta.place(x=30, y=10)
  55. caja_nombre = tk.Entry()
  56. caja_nombre.place(x=100, y=10, width=150, height=25)
  57.  
  58. # campo email
  59. etiqueta = tk.Label(text="Email")
  60. etiqueta.place(x=30, y=60)
  61. caja_email = tk.Entry()
  62. caja_email.place(x=100, y=60, width=150, height=25)
  63.  
  64. # boton
  65. boton = ttk.Button(text="Guardar", command=guardar)
  66. boton.place(x=120, y=120, width=80, height=35)
  67.  
  68. # lista
  69. lista = tk.Listbox()
  70. lista.insert(0,"Python","C","Java")
  71. lista.place(x=10, y=180)
  72. boton = ttk.Button(text="Guardar", command=guardar_lista)
  73. boton.place(x=50, y=370)
  74.  
  75. # lista desplegable
  76. combobox = ttk.Combobox(
  77.         state="readonly",
  78.         values = ("Juan", "Ana", "Guillermina", "Victor")  
  79.             )
  80. combobox.place(x=50,y=400)
  81. boton = ttk.Button(text="Guardar", command=guardar_combo)
  82. boton.place(x=50, y=430)
  83.  
  84. # imagen dentro de una etiqueta
  85. imagen = tk.PhotoImage(file="camion.png")
  86. label = ttk.Label(image=imagen)
  87. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  88.  
  89. # casilla de verificacion
  90. estado = tk.BooleanVar()
  91. estado.set("False")
  92. casilla = ttk.Checkbutton(text="Aceptar términos y condiciones", variable=estado)
  93. casilla.place(x=50, y=480)
  94.  
  95.  
  96.  
  97.  
  98. ventana.mainloop()
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement