Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PDG Tkinter Uygulaması
import tkinter
import sqlite3
db = sqlite3.connect("veritabani.db")
cursor = db.cursor()
def OgrenciEkle():
ogrenciNo = tbOgrNo.get()
ogrenciAdi = tbOgrAdi.get()
cursor.execute("INSERT INTO ogrenciler VALUES (?,?)",[ogrenciNo,ogrenciAdi])
db.commit()
tbOgrNo.delete(0,'end')
tbOgrAdi.delete(0,'end')
listele()
def OgrenciSil():
ad = lbOgrenci.get(lbOgrenci.curselection())[1]
cursor.execute("DELETE FROM ogrenciler WHERE ogrenciAdi = ?",[ad])
db.commit()
listele()
def DersEkle():
dersKodu = tbDersKodu.get()
dersAdi = tbDersAdi.get()
cursor.execute("INSERT INTO dersler VALUES (?,?)",[dersKodu,dersAdi])
db.commit()
tbDersKodu.delete(0,'end')
tbDersAdi.delete(0,'end')
listele()
def DersSil():
ad = lbDers.get(lbDers.curselection())[1]
cursor.execute("DELETE FROM dersler WHERE dersAdi = ?",[ad])
db.commit()
listele()
def OgrenciDersEkle():
ogrNo = lbOgrenci.get(lbOgrenci.curselection())[0]
dersKodu = lbDers.get(lbDers.curselection())[0]
cursor.execute("INSERT INTO ogrenciDers (ogrenciNo,dersKodu) VALUES (?,?)",[ogrNo,dersKodu])
db.commit()
listele()
def OgrenciDersSil():
liste = lbOgrenciDers.get(lbOgrenciDers.curselection())
ogrAdi = liste[0]
dersAdi = liste[1]
cursor.execute("SELECT ogrenciNo FROM ogrenciler WHERE ogrenciAdi = ?",[ogrAdi])
ogrNo= cursor.fetchone()
cursor.execute("SELECT dersKodu FROM dersler WHERE dersAdi = ?",[dersAdi])
dersKodu = cursor.fetchone()
cursor.execute("DELETE FROM ogrenciDers WHERE dersKodu = ? AND ogrenciNo = ?",[dersKodu[0],ogrNo[0]])
db.commit()
listele()
def listele():
index = 0
lbOgrenci.delete(0,"end")
cursor.execute("SELECT * FROM ogrenciler")
for i in cursor.fetchall():
lbOgrenci.insert(index,i)
index+=1
index = 0
lbDers.delete(0,"end")
cursor.execute("SELECT * FROM dersler")
for i in cursor.fetchall():
lbDers.insert(index,i)
index+=1
index = 0
lbOgrenciDers.delete(0,"end")
cursor.execute("SELECT ogrenciAdi,dersAdi FROM ogrenciler o,ogrenciDers od, dersler d WHERE o.OgrenciNo = od.OgrenciNo AND od.DersKodu = d.DersKodu")
for i in cursor.fetchall():
lbOgrenciDers.insert(index,i)
index+=1
frmMain = tkinter.Tk()
#LABEL
lblOgrNo = tkinter.Label(frmMain,text = "Öğrenci Numarası")
lblOgrNo.grid(column = 0, row = 0)
lblOgrAdi = tkinter.Label(frmMain,text = "Öğrenci Adı")
lblOgrAdi.grid(column = 0, row = 1)
lblDersKodu = tkinter.Label(frmMain,text = "Ders Kodu")
lblDersKodu.grid(column = 3, row = 0)
lblDersAdi = tkinter.Label(frmMain,text = "Ders Adı")
lblDersAdi.grid(column = 3, row = 1)
#ENTRY
tbOgrNo = tkinter.Entry(frmMain)
tbOgrNo.grid(column = 1,row = 0)
tbOgrAdi = tkinter.Entry(frmMain)
tbOgrAdi.grid(column = 1,row = 1)
tbDersKodu = tkinter.Entry(frmMain)
tbDersKodu.grid(column = 4,row = 0)
tbDersAdi = tkinter.Entry(frmMain)
tbDersAdi.grid(column = 4,row = 1)
#BUTTON
btnOgrenciEkle = tkinter.Button(frmMain,text="Öğrenci Ekle",command = OgrenciEkle)
btnOgrenciEkle.grid(column = 0, row = 5)
btnOgrenciSil = tkinter.Button(frmMain,text="Öğrenci Sil",command = OgrenciSil)
btnOgrenciSil.grid(column = 1, row = 5)
btnDersEkle = tkinter.Button(frmMain,text="Ders Ekle",command = DersEkle)
btnDersEkle.grid(column = 3, row = 5)
btnDersSil = tkinter.Button(frmMain,text="Ders Sil",command = DersSil)
btnDersSil.grid(column = 4, row = 5)
btnOgrenciDersEkle = tkinter.Button(frmMain,text="Öğrenciye Ders Ekle", command = OgrenciDersEkle)
btnOgrenciDersEkle.grid(column = 5, row = 5)
btnOgrenciDersSil = tkinter.Button(frmMain,text="Öğrenciden Ders Sil", command = OgrenciDersSil)
btnOgrenciDersSil.grid(column = 6, row = 5)
#LISTBOX
lbOgrenci = tkinter.Listbox(frmMain,exportselection=0)
lbOgrenci.grid(column=1,row=2,rowspan=3)
lbDers = tkinter.Listbox(frmMain,exportselection=0)
lbDers.grid(column=4,row=2,rowspan=3)
lbOgrenciDers = tkinter.Listbox(frmMain)
lbOgrenciDers.grid(column=5,row=2,columnspan=2,rowspan=3)
listele()
frmMain.mainloop()
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment