Conversor de longitud usando Python y Tkinter

Jan 16 2023
.

import tkinter as tk

def convert_to_meters():
    feet = float(feet_entry.get())
    meters = feet * 0.3048
    meters_label.config(text=meters)

def convert_to_centimeters():
    inches = float(inches_entry.get())
    centimeters = inches * 2.54
    centimeters_label.config(text=centimeters)

root = tk.Tk()
root.title("Length Converter")

feet_label = tk.Label(root, text="Feet:")
feet_label.grid(row=0, column=0)

feet_entry = tk.Entry(root)
feet_entry.grid(row=0, column=1)

meters_button = tk.Button(root, text="Convert to Meters", command=convert_to_meters)
meters_button.grid(row=1, column=0, columnspan=2, pady=10)

meters_label = tk.Label(root, text="")
meters_label.grid(row=2, column=0, columnspan=2)

inches_label = tk.Label(root, text="Inches:")
inches_label.grid(row=3, column=0)

inches_entry = tk.Entry(root)
inches_entry.grid(row=3, column=1)

centimeters_button = tk.Button(root, text="Convert to Centimeters", command=convert_to_centimeters)
centimeters_button.grid(row=4, column=0, columnspan=2, pady=10)

centimeters_label = tk.Label(root, text="")
centimeters_label.grid(row=5, column=0, columnspan=2)

root.mainloop()

© Copyright 2021 - 2023 | unogogo.com | All Rights Reserved