Advertisement
teslariu

conversor temp

Sep 8th, 2022
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Script que implementa un convertidor de temperaturas de ºF a ºC y viceversa
  4.  
  5. import tkinter as tk
  6.  
  7.  
  8. def pasar_a_celsius():
  9.     caja_celsius.delete(0,tk.END)
  10.     temp = (int(caja_farenheit.get()) - 32) / 1.8
  11.     caja_celsius.insert('insert',f"{temp:.1f}")
  12.    
  13. def pasar_a_farenheit():
  14.     caja_farenheit.delete(0,tk.END)
  15.     temp = int(caja_celsius.get()) * 1.8 + 32
  16.     caja_farenheit.insert('insert',f"{temp:.1f}")
  17.    
  18.  
  19.  
  20.  
  21. ventana = tk.Tk()
  22. ventana.config(width=400, height=200)
  23. ventana.title("Conversor de temperaturas")
  24. ventana.minsize(320,120)
  25.  
  26.  
  27.  
  28. # Campo Celsius
  29. etiqueta = tk.Label(text="ºC")
  30. etiqueta.place(x=25, y=25)
  31. caja_celsius = tk.Entry()
  32. caja_celsius.place(x=70, y=25, width=50, height=25)
  33.  
  34. # Campo email
  35. etiqueta = tk.Label(text="ºF")
  36. etiqueta.place(x=175, y=25)
  37. caja_farenheit = tk.Entry()
  38. caja_farenheit.place(x=220, y=25, width=50, height=25)
  39.  
  40.  
  41. boton = tk.Button(text="ºC -> ºF", command=pasar_a_farenheit)
  42. boton.place(x=40, y=80, width=70, height=30)
  43.  
  44. boton = tk.Button(text="ºF -> ºC", command=pasar_a_celsius)
  45. boton.place(x=190, y=80, width=70, height=30)
  46.  
  47. ventana.mainloop()
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement