Project Features
Basic Operations
+, -, ร, รท, %, parentheses, constants (ฯ, e)
Scientific Functions
sin, cos, tan, log, โ, xสธ, factorial, combinations
Memory & History
M+, M-, MR, MC, calculation history with export
Professional UI
Dark theme, animations, responsive layout, keyboard support
Live Calculator Preview
23,456.78
Complete Calculator Code
import tkinter as tk
from tkinter import ttk
import math
import cmath
class ScientificCalculator:
def __init__(self, root):
self.root = root
self.root.title("Scientific Calculator")
self.root.geometry("400x650")
self.root.configure(bg='#1a1a2e')
# Variables
self.current = "0"
self.previous = ""
self.operation = ""
self.memory = 0
self.history = []
self.setup_ui()
def setup_ui(self):
# Display
self.display_var = tk.StringVar(value="0")
display = tk.Entry(self.root, textvariable=self.display_var,
font=('SF Mono', 24, 'bold'), justify='right',
bg='#0f0f23', fg='#10B981', bd=0, readonly=True)
display.grid(row=0, column=0, columnspan=5, padx=20, pady=20, ipady=20)
# Buttons
buttons = [
('C', 1, 0), ('ยฑ', 1, 1), ('%', 1, 2), ('รท', 1, 3),
('sin', 2, 0), ('cos', 2, 1), ('tan', 2, 2), ('ร', 2, 3),
('7', 3, 0), ('8', 3, 1), ('9', 3, 2), ('-', 3, 3),
('4', 4, 0), ('5', 4, 1), ('6', 4, 2), ('+', 4, 3),
('1', 5, 0), ('2', 5, 1), ('3', 5, 2), ('=', 5, 3),
('0', 6, 0), ('.', 6, 2), ('โ', 6, 3)
]
for (text, row, col) in buttons:
self.create_button(text, row, col)
def create_button(self, text, row, col, colspan=1):
btn = tk.Button(self.root, text=text, font=('Inter', 16, 'bold'),
bg='#2d2d44', fg='white', bd=0, padx=20, pady=20,
command=lambda t=text: self.button_click(t),
relief='flat', cursor='hand2')
btn.grid(row=row, column=col, padx=8, pady=8, ipadx=25, ipady=25,
sticky='nsew', columnspan=colspan)
btn.bind('', lambda e: btn.configure(bg='#3d3d5a'))
btn.bind('', lambda e: btn.configure(bg='#2d2d44'))
def button_click(self, char):
if char == 'C':
self.current = "0"
elif char == '=':
self.calculate()
elif char in '+-รรท':
self.operation = char
self.previous = self.current
self.current = "0"
elif char == '.':
if '.' not in self.current:
self.current += char
else:
if self.current == "0":
self.current = char
else:
self.current += char
self.display_var.set(self.current)
def calculate(self):
try:
prev = float(self.previous)
curr = float(self.current)
if self.operation == '+': result = prev + curr
elif self.operation == '-': result = prev - curr
elif self.operation == 'ร': result = prev * curr
elif self.operation == 'รท': result = prev / curr if curr != 0 else "Error"
self.current = str(result)
self.history.append(f"{self.previous} {self.operation} {self.current} = {result}")
except:
self.current = "Error"
self.display_var.set(self.current)
# Run app
if __name__ == "__main__":
root = tk.Tk()
app = ScientificCalculator(root)
root.mainloop()
Advanced Features Implementation
# Scientific functions
def scientific_function(self, func):
try:
value = float(self.current)
if func == 'sin': result = math.sin(math.radians(value))
elif func == 'cos': result = math.cos(math.radians(value))
elif func == 'tan': result = math.tan(math.radians(value))
elif func == 'log': result = math.log10(value)
elif func == 'โ': result = math.sqrt(value)
self.current = str(round(result, 6))
except:
self.current = "Error"
# Memory functions
def memory_add(self): self.memory += float(self.current)
def memory_recall(self): self.current = str(self.memory)
def memory_clear(self): self.memory = 0
# History panel (new window)
def show_history(self):
hist_window = tk.Toplevel(self.root)
hist_window.title("Calculation History")
for calc in self.history[-20:]:
tk.Label(hist_window, text=calc, bg='#1a1a2e', fg='white').pack(pady=2)
Professional Theming
# Dark theme configuration
THEME = {
'bg': '#1a1a2e',
'display_bg': '#0f0f23',
'btn_bg': '#2d2d44',
'btn_hover': '#3d3d5a',
'primary': '#10B981',
'secondary': '#F59E0B',
'accent': '#EF4444'
}
# Button animations
def animate_button_press(self, btn):
btn.configure(bg=THEME['btn_hover'])
self.root.after(100, lambda: btn.configure(bg=THEME['btn_bg']))
# Keyboard support
def on_keypress(self, event):
if event.char.isdigit() or event.char in '+-*/.()':
self.button_click(event.char)
elif event.keysym == 'Return':
self.calculate()
elif event.keysym == 'Escape':
self.button_click('C')
self.root.bind('', self.on_keypress)
Production Deployment
# requirements.txt
"""
tkinter
PyInstaller==5.13.2
"""
# Build executable (Windows/Mac/Linux)
# pip install pyinstaller
pyinstaller --onefile --windowed --icon=calc.ico calculator.py
# Advanced: Auto-updater
import requests
def check_updates():
latest = requests.get('https://api.github.com/repos/user/calc/releases/latest')
# Auto-download updates
# Cross-platform installer
# Create .dmg (Mac), .exe (Windows), .deb (Linux)
Windows .exe
One-click install
One-click install
macOS .dmg
App Store ready
App Store ready
Linux .deb
Distribution ready
Distribution ready
Pro Challenges
1. Graphing Calculator
Plot functions (sin(x), xยฒ) with Matplotlib integration
2. Unit Converter
Length, weight, temperature, currency with real-time rates
3. Matrix Calculator
Matrix operations using NumPy (determinant, inverse)
4. Financial Calculator
Mortgage, compound interest, IRR, NPV calculations
GUI Developer Ready!
๐ฅ๏ธ Production GUI Applications:
๐ผ Desktop Apps
Tools, utilities, dashboards
Tools, utilities, dashboards
๐ฑ Cross-Platform
Windows/Mac/Linux deployment
Windows/Mac/Linux deployment
๐จ Professional UI
Themes, animations, accessibility
Themes, animations, accessibility
๐ Production Ready
Installers, auto-update, packaging
Installers, auto-update, packaging
๐ฐ Portfolio Project
GitHub showcase + executable
GitHub showcase + executable
Build, package, and distribute professional desktop applications! ๐