The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a temperature converter GUI

Here’s a simple Temperature Converter GUI using Python and the tkinter library:

python
import tkinter as tk from tkinter import ttk def convert_temperature(): try: temp = float(entry_temp.get()) if temp_type.get() == "Celsius to Fahrenheit": result = (temp * 9/5) + 32 result_label.config(text=f"{result:.2f} °F") else: result = (temp - 32) * 5/9 result_label.config(text=f"{result:.2f} °C") except ValueError: result_label.config(text="Invalid input") # Create main window root = tk.Tk() root.title("Temperature Converter") root.geometry("300x200") root.resizable(False, False) # Input label and entry entry_label = ttk.Label(root, text="Enter Temperature:") entry_label.pack(pady=5) entry_temp = ttk.Entry(root, width=20) entry_temp.pack(pady=5) # Dropdown for conversion type temp_type = tk.StringVar(value="Celsius to Fahrenheit") conversion_menu = ttk.Combobox(root, textvariable=temp_type, values=["Celsius to Fahrenheit", "Fahrenheit to Celsius"], state="readonly") conversion_menu.pack(pady=5) # Convert button convert_button = ttk.Button(root, text="Convert", command=convert_temperature) convert_button.pack(pady=10) # Result display result_label = ttk.Label(root, text="", font=("Helvetica", 14)) result_label.pack(pady=10) # Start the GUI event loop root.mainloop()

Features:

  • Converts between Celsius and Fahrenheit.

  • Validates numeric input.

  • Uses ttk for a clean look.

Requirements:

This runs with any standard Python installation (Python 3.x), as tkinter is included by default.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About