teslariu

conversion de temp

Jul 22nd, 2022
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import tkinter as tk   #binding de TCL/Tk
  5. import pprint
  6.  
  7. # Programa que convierte temperaturas
  8.  
  9.  
  10. def pasar_a_celsius():
  11.     caja_celsius.delete(0,tk.END)
  12.     temp = (float(caja_farenheit.get()) - 32) / 1.8
  13.     temp = f"{temp:.1f}"
  14.     caja_celsius.insert(3,temp)
  15.    
  16. def pasar_a_farenheit():
  17.     caja_farenheit.delete(0,tk.END)
  18.     temp = float(caja_celsius.get()) * 1.8 + 32
  19.     temp = f"{temp:.1f}"
  20.     caja_farenheit.insert(3,temp)
  21.  
  22.  
  23.  
  24. ventana = tk.Tk()
  25. ventana.config(width=400, height=300)
  26. ventana.title("Conversión de temperaturas")
  27. ventana.resizable(0,0)
  28.  
  29. ######### campo celsius ###########################
  30.  
  31. caja_celsius = tk.Entry()
  32. caja_celsius.place(x=150, y=30, width=100, height=25)
  33. etiqueta = tk.Label(text="Temperatura (ºC)")
  34. etiqueta.place(x=20, y=30)
  35.  
  36.  
  37. ######### campo farenheit ###########################
  38.  
  39. caja_farenheit = tk.Entry()
  40. caja_farenheit.place(x=150, y=90, width=100, height=25)
  41. etiqueta = tk.Label(text="Temperatura (ºF)")
  42. etiqueta.place(x=20, y=90)
  43.  
  44.  
  45.  
  46. # botones
  47. boton = tk.Button(text="Pasar a ºC", command=pasar_a_celsius)
  48. boton.place(x=30, y=150, width=100, height=50)
  49. boton = tk.Button(text="Pasar a ºF", command=pasar_a_farenheit)
  50. boton.place(x=200, y=150, width=100, height=50)
  51.  
  52.  
  53. ventana.mainloop()
  54.  
Advertisement
Add Comment
Please, Sign In to add comment