Kaskus

Tech

misterFanatickAvatar border
TS
misterFanatick
[ASK] Pemprograman Python
Halo agan - agan semua
sebelumnya udah pada tau kan pemprograman Python seperti apa ?
nah ane lagi iseng - iseng nih buat program pake bahasa Python pake Tkinter dan database Phpmysql

Langsung crot ke Coding yang ane buat beserta Bata error nya nih gan 70% work udah mohon pencerahan sapa tau ada yang mahir disini emoticon-Big Grin
Code:
from Tkinter import *
import Tkinter as tk
import MySQLdb

#misterFanatick

MainWindow = Tk()
MainWindow.title("Tkinter GUI")
MainWindow.geometry("600x300+100+100")
MainWindow.resizable(width=False,height=False)

def addEntry():
import MySQLdb as db
db = MySQLdb.connect("localhost","root","", "invendb" )
cursor=db.cursor()
sql="""insert into inventory("nama_barang", "harga_barang", "stock") VALUES ('%s','%s','%s')"""\
%(namaVar.get(),hargaVar.get(),stockVar.get())
#try:
cursor.execute(sql)
db.commit()
#print"Data Disimpan"
#except:
db.rollback()
#print"Kesalahan Koneksi Database"
db.close()
def deleteEntry():
import MySQLdb as db
db = MySQLdb.connect("localhost","root","", "invendb" )
cursor=db.cursor()
sql="""delete from inventory where id"""
try:
cursor.execute(sql)
db.commit()
print " Data Telah di Delete!"
except:
db.rollback()
print"Terjadi Kesalahan dalam database"
db.close()




#Label Nama Toko
Label1=Label(MainWindow,text='Program Inventory Toko Bunga',bg='green',fg='black',height=2,width=30)
Label1.pack(pady=5)

#Nama Barang
Label1=Label(MainWindow,text='Nama Barang',height=1,width=10)
Label1.place(x=10,y=45)
namaVar = StringVar()
Label1=Entry(MainWindow, textvariable=namaVar)
Label1.place(x=100,y=45)
#Harga Barang
Label2=Label(MainWindow,text='Harga Barang',height=1,width=10)
Label2.place(x=10,y=75)
hargaVar = StringVar()
Label2=Entry(MainWindow, textvariable=hargaVar)
Label2.place(x=100,y=75)
#Stock
Label3=Label(MainWindow,text='Stock Barang',height=1,width=10)
Label3.place(x=10,y=105)
stockVar = StringVar()
Label3=Entry(MainWindow, textvariable=stockVar)
Label3.place(x=100,y=105)

#List box
db = MySQLdb.connect("localhost","root","", "invendb" )
cursor = db.cursor()

sql="select * from inventory"

cursor.execute(sql)
result = cursor.fetchall()
for result in result:
nama_barang=result[0]
harga_barang=result[1]
stock=result[2]

listbox = Listbox(MainWindow)
listbox.pack()
listbox.insert(END, result)
db.close()

#Button
Button1=Button(MainWindow,text='ADD', width=9,command=addEntry)
Button1.place(x=100,y=250)
Button2=Button(MainWindow,text='DELETE', width=9,command=deleteEntry)
Button2.place(x=200,y=250)



MainWindow.mainloop()



ini pesan error nya
Code:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Users\Bayu\Documents\my project\newTA.py", line 17, in addEntry
cursor.execute(sql)
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'"nama_barang", "harga_barang", "stock") VALUES (\'dadad\',\'1234\',\'12\')\' at line 1')


Mohon pencerahan gan supaya gak tersesat di jalan setan merah
0
1.8K
5
GuestAvatar border
Komentar yang asik ya
Mari bergabung, dapatkan informasi dan teman baru!
Programmer Forum
Programmer Forum
KASKUS Official
20.2KThread5KAnggota
Urutkan
Terlama
GuestAvatar border
Komentar yang asik ya
Ikuti KASKUS di
© 2026 KASKUS, PT Darta Media Indonesia. All rights reserved.