Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python calculator with GUI using tkinter library. #205

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions Onik_0591.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import tkinter as tk
from tkinter import ttk

def calculate():
num1 = float(entry_num1.get())
num2 = float(entry_num2.get())
operation = int(operation_var.get())

if operation == 1:
result.set(num1 * num2)
elif operation == 2:
if num2 != 0:
result.set(num1 / num2)
else:
result.set("Error: Cannot divide by zero.")
elif operation == 3:
result.set(num1 - num2)
elif operation == 4:
result.set(num1 ** num2)
else:
result.set("Invalid operation")

# Create the main window
root = tk.Tk()
root.title("Fancy Calculator")
root.geometry("400x500")
root.configure(bg="#2c3e50")

# Create and place widgets
tk.Label(root, text="Fancy Calculator", font=('Helvetica', 16, 'bold'), bg="#2c3e50", fg="#ecf0f1").grid(row=0, column=0, columnspan=4, pady=10)

tk.Label(root, text="Enter the first number:", font=('Helvetica', 12), bg="#2c3e50", fg="#ecf0f1").grid(row=1, column=0, pady=5, padx=10, sticky="w")
entry_num1 = tk.Entry(root, font=('Helvetica', 12))
entry_num1.grid(row=1, column=1, pady=5, padx=10, columnspan=3, sticky="we")

tk.Label(root, text="Enter the second number:", font=('Helvetica', 12), bg="#2c3e50", fg="#ecf0f1").grid(row=2, column=0, pady=5, padx=10, sticky="w")
entry_num2 = tk.Entry(root, font=('Helvetica', 12))
entry_num2.grid(row=2, column=1, pady=5, padx=10, columnspan=3, sticky="we")

tk.Label(root, text="Select the operation:", font=('Helvetica', 12), bg="#2c3e50", fg="#ecf0f1").grid(row=3, column=0, pady=5, padx=10, sticky="w")
operation_var = tk.IntVar()
operation_var.set(1) # Default to multiplication
operations = [("Multiplication", 1), ("Division", 2), ("Subtraction", 3), ("Exponent", 4)]

for i, (text, value) in enumerate(operations):
tk.Radiobutton(root, text=text, variable=operation_var, value=value, bg="#2c3e50", fg="#ecf0f1").grid(row=3, column=i+1, padx=10, pady=5, sticky="w")

calculate_button = tk.Button(root, text="Calculate", command=calculate, font=('Helvetica', 12), bg="#3498db", fg="#ecf0f1", width=15, height=1)
calculate_button.grid(row=4, column=0, columnspan=4, pady=10, padx=10, sticky="we")

result = tk.StringVar()
result.set("Result will be shown here")
result_label = tk.Label(root, textvariable=result, font=('Helvetica', 12), bg="#2c3e50", fg="#ecf0f1")
result_label.grid(row=5, column=0, columnspan=4, pady=5, padx=10, sticky="we")

# Add some additional styling to make it more fancy
for widget in [entry_num1, entry_num2, calculate_button, result_label]:
widget.config(relief="solid", bd=2)

# Start the main loop
root.mainloop()
Binary file removed PythonFunctionCalculator.py
Binary file not shown.