Python
75 ~40 dk
GUI Programlama (Tkinter)
Tkinter ile GUI
import tkinter as tk
from tkinter import messagebox
class HesapMakinesi:
def __init__(self):
self.pencere = tk.Tk()
self.pencere.title("Hesap Makinesi")
self.pencere.geometry("300x200")
# Giriş alanları
tk.Label(self.pencere, text="1. Sayı:").pack(pady=5)
self.sayi1 = tk.Entry(self.pencere)
self.sayi1.pack()
tk.Label(self.pencere, text="2. Sayı:").pack(pady=5)
self.sayi2 = tk.Entry(self.pencere)
self.sayi2.pack()
# Butonlar
btn_frame = tk.Frame(self.pencere)
btn_frame.pack(pady=10)
tk.Button(btn_frame, text="+", command=lambda: self.hesapla("+"), width=5).grid(row=0, column=0, padx=2)
tk.Button(btn_frame, text="-", command=lambda: self.hesapla("-"), width=5).grid(row=0, column=1, padx=2)
tk.Button(btn_frame, text="×", command=lambda: self.hesapla("*"), width=5).grid(row=0, column=2, padx=2)
tk.Button(btn_frame, text="÷", command=lambda: self.hesapla("/"), width=5).grid(row=0, column=3, padx=2)
self.sonuc_label = tk.Label(self.pencere, text="Sonuç: ", font=("Arial", 14))
self.sonuc_label.pack(pady=10)
def hesapla(self, islem):
try:
a = float(self.sayi1.get())
b = float(self.sayi2.get())
sonuc = eval(f"{a} {islem} {b}")
self.sonuc_label.config(text=f"Sonuç: {sonuc:.2f}")
except:
messagebox.showerror("Hata", "Geçersiz giriş!")
def calistir(self):
self.pencere.mainloop()
app = HesapMakinesi()
app.calistir()💡 İpucu: Tkinter Python ile birlikte gelir, ek kurulum gerektirmez.
🎯 Alıştırmalar
- Tkinter ile to-do list uygulaması
- Tkinter ile basit not defteri