Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import tkinter as tk
- def convertir_a_C():
- temp = (float(caja_farenheit.get()) - 32) / 1.8
- temperatura.set(f"{temp:.1f}")
- def convertir_a_F():
- temp = float(caja_grados.get()) * 1.8 + 32
- temperatura.set(f"{temp:.1f}")
- ventana = tk.Tk()
- ventana.config(width= 400, height=150)
- ventana.resizable(0,0)
- ventana.title("Convertidor de temperatura")
- etiqueta = tk.Label(text="C")
- etiqueta.place(x=20, y=20)
- caja_grados = tk.Entry()
- caja_grados.place(x=40,y=20)
- etiqueta = tk.Label(text="F")
- etiqueta.place(x=200,y=20)
- caja_farenheit = tk.Entry()
- caja_farenheit.place(x=230,y=20)
- # Creo un botón C° A F°
- boton = tk.Button(text="C°>>F°", command=convertir_a_F)
- boton.place(x=70, y=70, width=80, height=25)
- # Creo un botón F° A C°
- boton = tk.Button(text="F°>>C°", command=convertir_a_C)
- boton.place(x=250, y=70, width=80, height=25)
- # Si la etiqueta va a ser variable, tiene que mostrar UNA VARIABLE
- temperatura = tk.StringVar()
- temperatura.set("0")
- resultado = tk.Label(textvar = temperatura)
- resultado.place(x=180,y=120)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement