Python Öğreniyorum 36 – Hesap Makinesi ChatGPT
Python Öğreniyorum 36 – Hesap Makinesi ChatGPT. Bu videomuzda ChatGPT kullanarak Python programlama dilinde bir hesap makinesi geliştirdik. İyi seyirler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
import tkinter as tk def calculate(): try: expression = entry.get() result = eval(expression) entry.delete(0, tk.END) entry.insert(tk.END, str(result)) except: entry.delete(0, tk.END) entry.insert(tk.END, "Hata") def clear(): entry.delete(0, tk.END) entry2.delete(0, tk.END) def power(): try: a = float(entry.get()) b = float(entry2.get()) result = a ** b entry.delete(0, tk.END) entry.insert(tk.END, str(result)) except: entry.delete(0, tk.END) entry.insert(tk.END, "Hata") def percentage(): try: a = float(entry.get()) b = float(entry2.get()) result = (a * b) / 100 entry.delete(0, tk.END) entry.insert(tk.END, str(result)) except: entry.delete(0, tk.END) entry.insert(tk.END, "Hata") def add_number_to_entry(number): if entry.focus_get() == entry: entry.insert(tk.END, number) elif entry2.focus_get() == entry2: entry2.insert(tk.END, number) # Pencere oluşturma window = tk.Tk() window.title("Hesap Makinesi") # Giriş kutusu 1 entry = tk.Entry(window, width=30) entry.grid(row=0, column=0, columnspan=4) # Giriş kutusu 2 entry2 = tk.Entry(window, width=30) entry2.grid(row=1, column=0, columnspan=4) # Butonlar buttons = [ ("7", 2, 0), ("8", 2, 1), ("9", 2, 2), ("/", 2, 3), ("4", 3, 0), ("5", 3, 1), ("6", 3, 2), ("*", 3, 3), ("1", 4, 0), ("2", 4, 1), ("3", 4, 2), ("-", 4, 3), ("0", 5, 0), (".", 5, 1), ("=", 5, 2), ("+", 5, 3), ("C", 6, 0), ("^", 6, 1), # Üst alma butonu ("%", 6, 2) # Yüzde hesaplama butonu ] for button_text, row, column in buttons: if button_text == "C": button = tk.Button(window, text=button_text, width=10, command=clear) elif button_text == "^": button = tk.Button(window, text=button_text, width=5, command=power) elif button_text == "%": button = tk.Button(window, text=button_text, width=5, command=percentage) elif button_text == "=": button = tk.Button(window, text=button_text, width=10, command=calculate) else: button = tk.Button(window, text=button_text, width=5, command=lambda text=button_text: add_number_to_entry(text)) button.grid(row=row, column=column) # Grid düzenini yeniden boyutlandırma for i in range(4): window.grid_columnconfigure(i, weight=1) window.grid_rowconfigure(0, weight=1) # Ana döngüyü başlatma window.mainloop() |