Skip to content

Instantly share code, notes, and snippets.

@eserdinyo
Last active May 29, 2018 23:53
Show Gist options
  • Save eserdinyo/f236ce383f8ae9e3121af0074ac34928 to your computer and use it in GitHub Desktop.
Save eserdinyo/f236ce383f8ae9e3121af0074ac34928 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import MySQLdb
import Tkinter
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
from Tkinter import *
from ttk import *
db = MySQLdb.connect("localhost", "root", "12345678", "python")
cursor = db.cursor()
def list():
sql = "SELECT * FROM products"
cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
liste.insert("",0,text=row[0], values=(row[1], row[2]))
def Ara():
id = ent1.get()
sql = "SELECT * FROM products WHERE Id = '%s'" % id
cursor.execute(sql)
result = cursor.fetchone()
ent2.delete(0, END)
ent3.delete(0, END)
ent2.insert(0, result[1])
ent3.insert(0, result[2])
def Guncelle():
id = ent1.get()
name = ent2.get()
type = ent3.get()
sql = "UPDATE products SET name = '%s', type='%s' WHERE Id = %s" %(name, type, id)
cursor.execute(sql)
db.commit()
menu = Tk()
label1 = Label(menu, text="Id").grid(row=1, column=1)
ent1 = Entry(menu)
ent1.grid(row=1, column=2)
label2 = Label(menu, text="Name").grid(row=2, column=1)
ent2 = Entry(menu)
ent2.grid(row=2, column=2)
label3 = Label(menu, text="Tip").grid(row=3, column=1)
ent3 = Combobox(menu)
ent3.grid(row=3, column=2)
ent3['values'] = ('Bilisim', 'Ev Aletleri', 'Besin')
ent3.current(0)
liste = Treeview(menu)
liste.grid(row=4, column=2)
liste['columns'] = 'sut1', 'sut2'
liste.heading('#0',text="ID")
liste.heading('sut1', text="Name")
liste.heading('sut2', text="Type")
btnGuncelle = Button(menu, text="Guncelle", command= Guncelle).grid(row=5, column=2)
btnAra = Button(menu, text="Ara", command = Ara).grid(row=5, column=3)
list()
menu.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment