Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # posicionamiento PLACE
- import tkinter as tk
- from tkinter import ttk
- # creo una ventana y la abro
- ventana = tk.Tk()
- # pongo un titulo
- ventana.title("Posicionamiento PLACE")
- # configuo el tamaño inicial
- ventana.configure(width=400, height=800)
- ############### funciones #######################
- def sumar():
- a = float(primer_sumando.get())
- b = float(segundo_sumando.get())
- print(f"{a} + {b} = {a+b}")
- total.set(str(a+b))
- def seleccion_listbox():
- posicion_cursor = lista.curselection()
- seleccion = lista.get(posicion_cursor)
- print(seleccion)
- def seleccion_combobox():
- seleccion = combo.get()
- print(seleccion)
- def guardar():
- estado = bool(estado_casilla.get())
- if estado:
- print("Ha aceptado las condiciones")
- else:
- print("Debe aceptar las condiciones")
- #####################################################
- total = tk.StringVar()
- total.set("0")
- # botón con ancho y alto por defecto
- boton = ttk.Button(text="SUMAR", command=sumar)
- boton.place(x=50, y=10)
- ############ campo del primer sumando ################
- primer_sumando = ttk.Entry()
- primer_sumando.place(x=50, y=60, width=100, height=25)
- etiqueta = ttk.Label(text="Ingrese el primer sumando")
- etiqueta.place(x=170, y=60)
- ############ campo del segundo sumando ################
- segundo_sumando = ttk.Entry()
- segundo_sumando.place(x=50, y=110, width=100, height=25)
- etiqueta = ttk.Label(text="Ingrese el segundo sumando")
- etiqueta.place(x=170, y=110)
- ############ campo de resultados ################
- resultado = ttk.Entry(
- font = ('arial',12,'italic'),
- textvariable = total,
- state = tk.DISABLED,
- )
- resultado.place(x=50, y=160, width=100, height=25)
- etiqueta = ttk.Label(text="Total")
- etiqueta.place(x=170, y=160)
- ############ otros widgets #########################
- ##### listbox
- lista = tk.Listbox()
- lista.insert(0,"Python", "C", "C++", "Java")
- lista.place(x=10, y=200)
- boton = ttk.Button(text="Guardar selección", command=seleccion_listbox)
- boton.place(x=10, y=370)
- ##### combobox
- combo = ttk.Combobox(state="readonly",values=["Erlang","GO","Javascript"])
- combo.place(x=10, y=420)
- boton = ttk.Button(text="Guardar combobox", command=seleccion_combobox)
- boton.place(x=10, y=450)
- ##### checkbutton
- estado_casilla = tk.BooleanVar()
- estado_casilla.set("True")
- casilla = ttk.Checkbutton(text="Acepto las condiciones", variable=estado_casilla)
- casilla.place(x=10, y=500)
- boton = ttk.Button(text="Guardar", command=guardar)
- boton.place(x=10, y=550)
- ### imagenes (dentro de una etiqueta: bmp, png, gif):
- imagen = tk.PhotoImage(file="camion.png")
- label = ttk.Label(image=imagen)
- label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
- # mantengo la ventana abierta
- ventana.mainloop()
Add Comment
Please, Sign In to add comment