Advertisement
teslariu

conversor

Feb 11th, 2022
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Hacer un script con dos campos: uno para ingresar temperaturas en ºC
  6. y otro campo para mostrarlas en ºF. Además, hacer un botón para mostrar
  7. la conversión
  8. formula: ºF = ºC * 1.8 + 32
  9.  
  10. """
  11. import tkinter as tk
  12.  
  13. def convertir():
  14.     temperatura = float(caja_centigrados.get())
  15.     temperatura = str(temperatura * 1.8 + 32)
  16.     resultado.set(temperatura)
  17.  
  18.  
  19.  
  20. ventana = tk.Tk()
  21. ventana.title("Conversor de temperaturas")
  22. ventana.config(width=400, height=300, bg="light steel blue")
  23. ventana.resizable(0,0)  # impido el redimensionamiento de la ventana
  24.  
  25. # creo la variable gráfica para mostrar la temp enºF
  26. resultado = tk.StringVar()
  27. resultado.set("0")
  28.  
  29. # campo celsius
  30. etiqueta = tk.Label(
  31.             text="Temperatura (ºC)",
  32.             bg="light steel blue",
  33.             font=('arial',12,'italic')
  34.             )
  35. etiqueta.place(x=30, y=50)
  36.  
  37. caja_centigrados = tk.Entry(
  38.                     font=('arial',13),
  39.                     justify='right'
  40.                     )
  41. caja_centigrados.place(x=200, y=50, width=80, height=30)
  42.  
  43. # campo farenheit
  44. etiqueta = tk.Label(
  45.             text="Temperatura (ºF)",
  46.             bg="light steel blue",
  47.             font=('arial',12,'italic')
  48.             )
  49. etiqueta.place(x=30, y=120)
  50.  
  51. caja_farenheit = tk.Entry(
  52.                     font=('arial',13),
  53.                     justify='right',
  54.                     state=tk.DISABLED,
  55.                     textvariable=resultado
  56.                     )
  57. caja_farenheit.place(x=200, y=120, width=80, height=30)
  58.  
  59.  
  60. # boton
  61. boton = tk.Button(text="CONVERTIR\nTEMPERATURA", command=convertir)
  62. boton.place(x=150, y=200)
  63.  
  64. ventana.mainloop()
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement