Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # place
- import tkinter as tk
- from tkinter import ttk
- from tkinter import messagebox
- from pprint import pprint
- main = tk.Tk()
- main.title("Mi primera app")
- main.config(width=400, height=800)
- datos = []
- def guardar_nombre():
- global datos
- nombre = caja_nombre.get()
- tel = caja_tel.get()
- dato = {"nombre": nombre, "telefono":tel}
- datos.append(dato)
- print()
- pprint(datos)
- # muestro un mensaje
- messagebox.showinfo(title="INFO", message="Datos guardados correctamente")
- # borro los campos del formulario
- caja_nombre.delete(0, tk.END)
- caja_tel.delete(0, tk.END)
- def guardar_lista():
- print(lista.get(lista.curselection()))
- def guardar_combo():
- valor = combo.get()
- print(valor)
- # para evitar redimensionamiento
- # main.resizable(0,0)
- # Campos de datos de un formulario
- # campo nombre
- caja_nombre = ttk.Entry()
- caja_nombre.place(x=90, y=10, width=150, height=25)
- etiqueta = ttk.Label(text="Nombre")
- etiqueta.place(x=10, y=10)
- # campo TE
- caja_tel = ttk.Entry()
- caja_tel.place(x=90, y=60, width=150, height=25)
- etiqueta = ttk.Label(text="TEL")
- etiqueta.place(x=10, y=60)
- boton = ttk.Button(text="Guardar datos", command=guardar_nombre)
- boton.place(x=60, y=100, width=120, height=50)
- # lista (listbox)
- lista = tk.Listbox()
- lista.insert(0, "Python", "C", "Java")
- lista.place(x=10, y=150)
- boton = ttk.Button(text="Guardar", command=guardar_lista)
- boton.place(x=10, y=330)
- # imagen dentro de una etiqueta
- imagen = tk.PhotoImage(file="camion2.png")
- et = ttk.Label(image=imagen)
- et.place(relx=0.50, rely=0.5, relwidth=0.5, relheight=0.5)
- # lista desplegable (combobox)
- combo = ttk.Combobox(state='readonly',
- values = [1,2,30,400,5000,"infinito"]
- )
- combo.place(x=10, y=360)
- boton = ttk.Button(text="Guardar", command=guardar_combo)
- boton.place(x=10, y=390)
- # casilla de verificación
- estado = tk.BooleanVar()
- estado.set("True")
- casilla = ttk.Checkbutton(text="Acepto términos y condiciones", variable=estado)
- casilla.place(x=100, y=390)
- # barra de progreso
- barra = ttk.Progressbar(maximum=100)
- barra.place(x=10, y=550, width=200)
- barra.step(20)
- barra.start(10)
- barraV = ttk.Progressbar(orient=tk.VERTICAL, maximum=100)
- barraV.place(x=300, y=550, height=200)
- barraV.step(20)
- barraV.start(10)
- main.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment