Tabii, Windows'taki Hesap Makinesi uygulamasının tüm fonksiyonlarını içeren daha kapsamlı bir Python uygulaması oluşturalım. Bu uygulamada, temel aritmetik işlemlerin yanı sıra, trigonometrik fonksiyonlar, logaritmalar, faktöriyel, modül işlemleri gibi daha gelişmiş matematiksel işlemleri de ekleyeceğiz. Yine tkinter kütüphanesini kullanarak bir GUI oluşturacağız.
Aşağıda bu gereksinimlere uygun bir hesap makinesi uygulamasını sıfırdan oluşturacağız:
import tkinter as tk
from tkinter import messagebox
import math
class Calculator:
def __init__(self, root):
self.root = root
self.root.title("Hesap Makinesi")
self.root.geometry("450x580")
self.equation = tk.StringVar()
self.entry_value = ''
self.create_widgets()
def button_click(self, value):
self.entry_value += str(value)
self.equation.set(self.entry_value)
def clear_entry(self):
self.entry_value = ''
self.equation.set(self.entry_value)
def delete_last(self):
self.entry_value = self.entry_value[:-1]
self.equation.set(self.entry_value)
def calculate(self):
try:
total = str(eval(self.entry_value))
self.equation.set(total)
self.entry_value = total
except Exception as e:
messagebox.showerror("Hata", "Geçersiz İşlem")
self.entry_value = ''
def create_widgets(self):
entry = tk.Entry(self.root, textvariable=self.equation, font=('Arial', 20), bd=10, insertwidth=2, width=15, borderwidth=4)
entry.grid(row=0, column=0, columnspan=5)
buttons = [
'7', '8', '9', '/', 'C',
'4', '5', '6', '*', 'del',
'1', '2', '3', '-', '(',
'0', '.', '=', '+', ')',
'sin', 'cos', 'tan', 'log', '√',
'x^2', 'x^y', '!', 'mod', 'π',
]
row_val = 1
col_val = 0
for button in buttons:
if button == '=':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=self.calculate)
elif button == 'C':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=self.clear_entry)
elif button == 'del':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=self.delete_last)
elif button == '√':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=lambda: self.button_click('math.sqrt('))
elif button == 'π':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=lambda: self.button_click('math.pi'))
elif button == 'sin':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=lambda: self.button_click('math.sin('))
elif button == 'cos':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=lambda: self.button_click('math.cos('))
elif button == 'tan':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=lambda: self.button_click('math.tan('))
elif button == 'log':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=lambda: self.button_click('math.log('))
elif button == 'x^2':
btn = tk.Button(self.root, text=button, padx=15, pady=20, font=('Arial', 12), command=lambda: self.button_click('**2'))
elif button == 'x^y':
btn = tk.Button(self.root, text=button, padx=15, pady=20, font=('Arial', 12), command=lambda: self.button_click('**'))
elif button == '!':
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=lambda: self.button_click('math.factorial('))
elif button == 'mod':
btn = tk.Button(self.root, text=button, padx=12, pady=20, font=('Arial', 12), command=lambda: self.button_click('%'))
else:
btn = tk.Button(self.root, text=button, padx=20, pady=20, font=('Arial', 12), command=lambda b=button: self.button_click(b))
btn.grid(row=row_val, column=col_val)
col_val += 1
if col_val > 4:
col_val = 0
row_val += 1
if __name__ == '__main__':
root = tk.Tk()
calculator = Calculator(root)
root.mainloop()
Bu uygulama çeşitli fonksiyonları içerir:
- Temel Aritmetik İşlemler: Toplama (+), çıkarma (-), çarpma (*), bölme (/).
- Özel Fonksiyonlar: Silme (del), temizleme (C), eşittir (=).
- Gelişmiş Matematiksel Fonksiyonlar:
- Kare (x^2)
- Üs alma (x^y)
- Karekök (√)
- Faktöriyel (!)
- Modül (mod)
- Sinüs (sin)
- Kosinüs (cos)
- Tanjant (tan)
- Logaritma (log)
- Pi (π)
Bu uygulama, kullanıcıların çeşitli matematiksel işlemleri kolayca yapabilmelerini sağlar. Her bir buton belirli bir işlevle ilişkilendirilmiştir ve kullanıcı tıkladığında ilgili işlemi gerçekleştirir. Uygulamayı çalıştırarak tüm işlevselliği test edebilirsiniz.