Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- """
- Hacer un script con dos campos: uno para ingresar temperaturas en ºC
- y otro campo para mostrarlas en ºF. Además, hacer un botón para mostrar
- la conversión
- formula: ºF = ºC * 1.8 + 32
- """
- import tkinter as tk
- def convertir():
- temperatura = float(caja_centigrados.get())
- temperatura = str(temperatura * 1.8 + 32)
- resultado.set(temperatura)
- ventana = tk.Tk()
- ventana.title("Conversor de temperaturas")
- ventana.config(width=400, height=300, bg="light steel blue")
- ventana.resizable(0,0) # impido el redimensionamiento de la ventana
- # creo la variable gráfica para mostrar la temp enºF
- resultado = tk.StringVar()
- resultado.set("0")
- # campo celsius
- etiqueta = tk.Label(
- text="Temperatura (ºC)",
- bg="light steel blue",
- font=('arial',12,'italic')
- )
- etiqueta.place(x=30, y=50)
- caja_centigrados = tk.Entry(
- font=('arial',13),
- justify='right'
- )
- caja_centigrados.place(x=200, y=50, width=80, height=30)
- # campo farenheit
- etiqueta = tk.Label(
- text="Temperatura (ºF)",
- bg="light steel blue",
- font=('arial',12,'italic')
- )
- etiqueta.place(x=30, y=120)
- caja_farenheit = tk.Entry(
- font=('arial',13),
- justify='right',
- state=tk.DISABLED,
- textvariable=resultado
- )
- caja_farenheit.place(x=200, y=120, width=80, height=30)
- # boton
- boton = tk.Button(text="CONVERTIR\nTEMPERATURA", command=convertir)
- boton.place(x=150, y=200)
- ventana.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement