teslariu

conversor de Temp

Oct 24th, 2022
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. Conversion de temperatura
  6. DESAFIO: extender para lograr la conversión de ºC --> ºF
  7. """
  8. import tkinter as tk
  9.  
  10.  
  11. def convertir():
  12.     temp = caja_farenheit.get()
  13.     temp = (float(temp) - 32) / 1.8
  14.     caja_celsius.delete(0,tk.END)
  15.     caja_celsius.insert(0,f"{temp:.1f}")
  16.    
  17.  
  18. ventana = tk.Tk()
  19. ventana.config(width=300, height=150)
  20. ventana.title("ºF -> ºC")
  21. # prohibo redimensionar la ventana
  22. ventana.resizable(False, False)
  23.  
  24.  
  25. etiqueta = tk.Label(text="ºF")
  26. etiqueta.place(x=10, y=10)
  27. caja_farenheit = tk.Entry()
  28. caja_farenheit.place(x=30, y=10, width=50, height=25)
  29.  
  30. etiqueta = tk.Label(text="ºC")
  31. etiqueta.place(x=150, y=10)
  32. caja_celsius = tk.Entry()
  33. caja_celsius.place(x=170, y=10, width=50, height=25)
  34.  
  35. # BOTON
  36. boton = tk.Button(text="ºF --> ºC", command=convertir)
  37. boton.place(x=80, y=80, width=120, height=40)
  38.  
  39.  
  40. ventana.mainloop()
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment