import tkinter as tk
def calculate_area():
try:
radius = float(entry_radius.get())
height = float(entry_height.get())
area = 2 * 3.14 * radius * (radius + height)
result_label.config(text=f"Area of the cylinder: {area}")
except ValueError:
result_label.config(text="Please enter valid numbers for radius and height.")
# Create the main window
root = tk.Tk()
root.title("Cylinder Area Calculator")
# Create labels and entry fields for radius and height
label_radius = tk.Label(root, text="Enter the radius:")
label_radius.pack()
entry_radius = tk.Entry(root)
entry_radius.pack()
label_height = tk.Label(root, text="Enter the height:")
label_height.pack()
entry_height = tk.Entry(root)
entry_height.pack()
# Button to calculate area
calculate_button = tk.Button(root, text="Calculate Area", command=calculate_area)
calculate_button.pack()
# Label to display the result
result_label = tk.Label(root, text="")
result_label.pack()
root.mainloop()
run it
Under discussion
Comments
- Popular
- New
- Old
You must be signed in to leave a comment
This page doesn't have any comments yet