0% found this document useful (0 votes)
15 views9 pages

TP9 Pemograman Visual - Akhmad Suhaimi - 2055201110007

The document summarizes a programming assignment to develop a CRUD application in Python with the following key points: 1. The assignment asks students to build upon their UTS design project by adding CRUD features to manage at least 30 records in a form. 2. Features that must be included are adding, updating, and deleting single records, as well as a feature to delete multiple selected records. 3. The program connects to a MySQL database and implements the CRUD functions along with a GUI to view, select, and manage the records.

Uploaded by

HAII Haii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views9 pages

TP9 Pemograman Visual - Akhmad Suhaimi - 2055201110007

The document summarizes a programming assignment to develop a CRUD application in Python with the following key points: 1. The assignment asks students to build upon their UTS design project by adding CRUD features to manage at least 30 records in a form. 2. Features that must be included are adding, updating, and deleting single records, as well as a feature to delete multiple selected records. 3. The program connects to a MySQL database and implements the CRUD functions along with a GUI to view, select, and manage the records.

Uploaded by

HAII Haii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Laporan Pratikum 9

PEMOGRAMAN VISUAL

Nama : Akhmad Suhaimi


NPM : 2055201110007

PROGRAM STUDI INFORMATIKA


FAKULTAS TEKNIK
UNIVERSITAS MUHAMMADIYAH BANJARMASIN

2022
Tugas (perorangan).
1. Berdasarkan UTS yang kalian buat, pilihlah kembangkanlah dari design yang
kalian buat sehingga dilengkapi fitur CRUD.
2. Tampilkan minimal 30 data dalam form tersebut.
3. Pada Fitur Delete data buatlah fitur yang dapat berfungsi delete multiple data.
import tkinter as tk
from tkinter import ttk, messagebox
import mysql.connector
from tkinter import *

def GetValue(event):
e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
row_id = listBox.selection()[0]
select = listBox.set(row_id)
e1.insert(0,select['nim'])
e2.insert(0,select['nama'])
e3.insert(0,select['prodi'])
e4.insert(0,select['keterangan'])

def Add():
nim = e1.get()
nama = e2.get()
prodi = e3.get()
keterangan = e4.get()

mysqldb=mysql.connector.connect(host="localhost",user="root",password="",d
atabase="suhai")
mycursor=mysqldb.cursor()
try:
sql = "INSERT INTO surat (nim,nama,prodi,keterangan) VALUES (%s,
%s, %s, %s)"
val = (nim,nama,prodi,keterangan)
mycursor.execute(sql, val)
mysqldb.commit()
messagebox.showinfo("information", "Data Berhasil Ditambahkan...")
e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
e1.focus_set()
except Exception as e:
messagebox.showinfo("information", "Data Gagal Ditambahkan...")
mysqldb.rollback()
mysqldb.close()

def update():
nim = e1.get()
nama = e2.get()
prodi = e3.get()
keterangan = e4.get()

mysqldb=mysql.connector.connect(host="localhost",user="root",password="",d
atabase="suhai")
mycursor=mysqldb.cursor()

try:
sql = "UPDATE surat SET nama= %s,prodi= %s,keterangan= %s where
nim= %s"
val = (nama,prodi,keterangan,nim)
mycursor.execute(sql, val)
mysqldb.commit()
messagebox.showinfo("information", "Data Berhasil DiUpdate...")

e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
e1.focus_set()

except Exception as e:

print(e)
mysqldb.rollback()
mysqldb.close()

def delete():
nim = e1.get()

mysqldb=mysql.connector.connect(host="localhost",user="root",password="",d
atabase="suhai")
mycursor=mysqldb.cursor()

try:
sql = "DELETE from surat where nim = %s"
val = (nim,)
mycursor.execute(sql, val)
mysqldb.commit()
messagebox.showinfo("information", "Data Berhasil Dihapus...")
e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
e1.focus_set()

except Exception as e:

print(e)
mysqldb.rollback()
mysqldb.close()

def selected():

mysqldb=mysql.connector.connect(host="localhost",user="root",password="",d
atabase="suhai")
mycursor=mysqldb.cursor()

try:
x = listBox.selection()
val = []
for record in x:
val.append(listBox.item(record, 'values')[0])

for record in x:
listBox.delete(record)
sql = "delete from surat where nim = %s"
mycursor.executemany(sql, [(a,) for a in val])
mysqldb.commit()
messagebox.showinfo("information", "Data Berhasil Dihapus...")
e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
e1.focus_set()

except Exception as e:

print(e)
mysqldb.rollback()
mysqldb.close()

def show():
mysqldb = mysql.connector.connect(host="localhost", user="root",
password="", database="suhai")
mycursor = mysqldb.cursor()
mycursor.execute("SELECT nim,nama,prodi,keterangan FROM surat")
records = mycursor.fetchall()
print(records)

for i, (nim,nama,prodi,keterangan) in enumerate(records, start=1):


listBox.insert("", "end", values=(nim,nama,prodi,keterangan))
mysqldb.close()

root = Tk()
root.geometry("800x500")
root.title('Data Surat Dispensasi')
root.config(bg='mediumturquoise')
global e1
global e2
global e3
global e4

tk.Label(root, text="Surat Dispensasi", fg="black", bg= "white" , font=(None,


30)).place(x=300, y=5)

tk.Label(root, text="nim").place(x=10, y=10)


Label(root, text="nama").place(x=10, y=40)
Label(root, text="prodi").place(x=10, y=70)
Label(root, text="keterangan").place(x=10, y=100)

e1 = Entry(root)
e1.place(x=140, y=10)

e2 = Entry(root)
e2.place(x=140, y=40)

e3 = Entry(root)
e3.place(x=140, y=70)

e4 = Entry(root)
e4.place(x=140, y=100)

Button(root, text="Add",command = Add, bg="light blue", height=3, width=


13).place(x=30, y=130)
Button(root, text="update",command = update, bg="light blue", height=3,
width= 13).place(x=140, y=130)
Button(root, text="Delete",command = delete, bg="light blue", height=3,
width= 13).place(x=250, y=130)
Button(root, text="selected",command = selected, bg="light blue", height=3,
width= 13).place(x=360, y=130)

cols = ('nim', 'nama','prodi','keterangan')


listBox = ttk.Treeview(root, columns=cols, show='headings',
selectmode="extended" )

for col in cols:


listBox.heading(col, text=col)
listBox.grid(row=1, column=0, columnspan=2)
listBox.place(x=10, y=200)

show()
listBox.bind('<Double-Button-1>',GetValue)
root.mainloop()

Hasil Run

Fitur Add, Update, dan delete


Untuk Fitur Delete Multiple
Ctrl + klik data yang ingin di hapus, lalu Klik Selected

You might also like