Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- import tkinter as tk #binding de TCL/Tk
- import pprint
- # Programa que convierte temperaturas
- def pasar_a_celsius():
- caja_celsius.delete(0,tk.END)
- temp = (float(caja_farenheit.get()) - 32) / 1.8
- temp = f"{temp:.1f}"
- caja_celsius.insert(3,temp)
- def pasar_a_farenheit():
- caja_farenheit.delete(0,tk.END)
- temp = float(caja_celsius.get()) * 1.8 + 32
- temp = f"{temp:.1f}"
- caja_farenheit.insert(3,temp)
- ventana = tk.Tk()
- ventana.config(width=400, height=300)
- ventana.title("Conversión de temperaturas")
- ventana.resizable(0,0)
- ######### campo celsius ###########################
- caja_celsius = tk.Entry()
- caja_celsius.place(x=150, y=30, width=100, height=25)
- etiqueta = tk.Label(text="Temperatura (ºC)")
- etiqueta.place(x=20, y=30)
- ######### campo farenheit ###########################
- caja_farenheit = tk.Entry()
- caja_farenheit.place(x=150, y=90, width=100, height=25)
- etiqueta = tk.Label(text="Temperatura (ºF)")
- etiqueta.place(x=20, y=90)
- # botones
- boton = tk.Button(text="Pasar a ºC", command=pasar_a_celsius)
- boton.place(x=30, y=150, width=100, height=50)
- boton = tk.Button(text="Pasar a ºF", command=pasar_a_farenheit)
- boton.place(x=200, y=150, width=100, height=50)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment