Advertisement
teslariu

conversor con etiquetas

Sep 8th, 2022
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import tkinter as tk
  4.  
  5. def convertir_a_C():
  6.     temp = (float(caja_farenheit.get()) - 32) / 1.8
  7.     temperatura.set(f"{temp:.1f}")
  8.    
  9. def convertir_a_F():
  10.     temp = float(caja_grados.get()) * 1.8 + 32
  11.     temperatura.set(f"{temp:.1f}")
  12.  
  13.  
  14. ventana = tk.Tk()
  15.  
  16. ventana.config(width= 400, height=150)
  17. ventana.resizable(0,0)
  18. ventana.title("Convertidor de temperatura")
  19.  
  20. etiqueta = tk.Label(text="C")
  21. etiqueta.place(x=20, y=20)
  22. caja_grados = tk.Entry()
  23. caja_grados.place(x=40,y=20)
  24.  
  25. etiqueta = tk.Label(text="F")
  26. etiqueta.place(x=200,y=20)
  27. caja_farenheit = tk.Entry()
  28. caja_farenheit.place(x=230,y=20)
  29.  
  30. # Creo un botón C° A F°
  31. boton = tk.Button(text="C°>>F°", command=convertir_a_F)
  32. boton.place(x=70, y=70, width=80, height=25)
  33.  
  34. # Creo un botón F° A C°
  35. boton = tk.Button(text="F°>>C°", command=convertir_a_C)
  36. boton.place(x=250, y=70, width=80, height=25)
  37.  
  38.  
  39. # Si la etiqueta va a ser variable, tiene que mostrar UNA VARIABLE
  40. temperatura = tk.StringVar()
  41. temperatura.set("0")
  42. resultado = tk.Label(textvar = temperatura)
  43. resultado.place(x=180,y=120)
  44.  
  45. ventana.mainloop()
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement