KETENTUAN GUGUSAN NADA TERPILIH DARI DATA DI TABEL Gn_Biru di DATAMUSIK.db
(Part-1)
Tolong perbaiki fungsi def display_selected_gugusan_nada(progres, mode): agar supaya dari data yang diambil dari tabel Gn'Biru memenuhi ketentuan berikut:
1.1. Jika id=1, progres 1 mode Naik, maka data yang terpilih adalah adalah di kolom Bass_1 data dari id 1 Bass_1, di kolom Trebel_1 data dari id 1 Trebel_1, di kolom Bass_2 data dari id 1 Bass_2, di kolom Trebel_2 data dari id 1 Trebel_2, di kolom Bass_3 data dari id 1 Bass_3.
1.2. Jika id=1 progres 2 mode Naik, maka data yang terpilih adalah di kolom Bass_1 data dari id 1 Bass_1, di kolom Trebel_1 data dari id 3 Trebel_1, di kolom Bass_2 data dari id 1 Bass_2, di kolom Trebel_2 data dari id 3 Trebel_2, di kolom Bass_3 data dari id 1 Bass_3.
1.3. Jika id=1 progres 3 mode Naik, maka data yang terpilih adalah di kolom Bass_1 data dari id 1 Bass_1, di kolom Trebel_1 data dari id 2 Trebel_1, di kolom Bass_2 data dari id 1 Bass_2, di kolom Trebel_2 data dari id 2 Trebel_2, di kolom Bass_3 data dari id 1 Bass_3.
1.4. Jika id=1, progres 1 mode Turun, maka data yang terpilih adalah di kolom Bass_1 data dari id 1 Bass_1, di kolom Trebel_1 data dari id 1 Trebel_1, di kolom Bass_2 data dari id 1 Bass_2.
1.5. Jika id=1 progres 2 mode Turun, maka data yang terpilih adalah di kolom Bass_1 data dari id 1 Bass_1, di kolom Trebel_1 data dari id 2 Trebel_1, di kolom Bass_2 data dari id 1 Bass_2.
1.6. Jika id=1 progres 3 mode Turun, maka data yang terpilih adalah di kolom Bass_1 data dari id 1 Bass_1, di kolom Trebel_1 data dari id 3 Trebel_1, di kolom Bass_2 data dari id 1 Bass_2.
2.1. Jika id=2, progres 1 mode Naik, maka data yang terpilih adalah di kolom Bass_1 data dari id 2 Bass_1, di kolom Trebel_1 data dari id 2 Trebel_1, di kolom Bass_2 data dari id 2 Bass_2, di kolom Trebel_2 data dari id 2 Trebel_2.
2.2. Jika id=2 progres 2 mode Naik, maka data yang terpilih adalah di kolom Bass_1 data dari id 2 Bass_1, di kolom Trebel_1 data dari id 1 Trebel_1, di kolom Bass_2 data dari id 2 Bass_2, di kolom Trebel_2 data dari id 1 Trebel_2.
2.3. Jika id=2 progres 3 mode Naik, maka data yang terpilih adalah di kolom Bass_1 data dari id 2 Bass_1, di kolom Trebel_1 data dari id 3 Trebel_1, di kolom Bass_2 data dari id 2 Bass_2, di kolom Trebel_2 data dari id 3 Trebel_2.
2.4. Jika id=2, progres 1 mode Turun, maka data yang terpilih adalah di kolom Bass_1 data dari id 2 Bass_1, di kolom Trebel_1 data dari id 2 Trebel_1, di kolom Bass_2 data dari id 2 Bass_2, di kolom Trebel_2 data dari id 2 Trebel_2.
2.5. Jika id=2 progres 2 mode Turun, maka data yang terpilih adalah di kolom Bass_1 data dari id 2 Bass_1, di kolom Trebel_1 data dari id 3 Trebel_1, di kolom Bass_2 data dari id 2 Bass_2, di kolom Trebel_2 data dari id 3 Trebel_2.
2.6. Jika id=2 progres 3 mode Turun, maka data yang terpilih adalah di kolom Bass_1 data dari id 2 Bass_1, di kolom Trebel_1 data dari id 1 Trebel_1, di kolom Bass_2 data dari id 2 Bass_2, di kolom Trebel_2 data dari id 1 Trebel_2.
3.1. Jika id=3, progres 1 mode Naik, maka data yang terpilih adalah di kolom Bass_1 data dari id 3 Bass_1, di kolom Trebel_1 data dari id 3 Trebel_1, di kolom Bass_2 data dari id 3 Bass_2.
2.2. Jika id=3 progres 2 mode Naik, maka data yang terpilih adalah di kolom Bass_1 data dari id 3 Bass_1, di kolom Trebel_1 data dari id 2 Trebel_1, di kolom Bass_2 data dari id 3 Bass_2.
2.3. Jika id=3 progres 3 mode Naik, maka data yang terpilih adalah di kolom Bass_1 data dari id 3 Bass_1, di kolom Trebel_1 data dari id 1 Trebel_1, di kolom Bass_2 data dari id 3 Bass_2.
2.4. Jika id=3, progres 1 mode Turun, maka data yang terpilih adalah adalah di kolom Bass_1 data dari id 3 Bass_1, di kolom Trebel_1 data dari id 3 Trebel_1, di kolom Bass_2 data dari id 3 Bass_2, di kolom Trebel_2 data dari id 3 Trebel_2, di kolom Bass_3 data dari id 3 Bass_3.
2.5. Jika id=3 progres 2 mode Turun, maka data yang terpilih adalah adalah di kolom Bass_1 data dari id 3 Bass_1, di kolom Trebel_1 data dari id 1 Trebel_1, di kolom Bass_2 data dari id 3 Bass_2, di kolom Trebel_2 data dari id 1 Trebel_2, di kolom Bass_3 data dari id 3 Bass_3.
2.6. Jika id=3 progres 3 mode Turun, maka data yang terpilih adalah adalah di kolom Bass_1 data dari id 3 Bass_1, di kolom Trebel_1 data dari id 2 Trebel_1, di kolom Bass_2 data dari id 3 Bass_2, di kolom Trebel_2 data dari id 2 Trebel_2, di kolom Bass_3 data dari id 3 Bass_3.
Berikut adalah implementasi fungsi `display_selected_gugusan_nada` berdasarkan ketentuan yang Anda berikan. Fungsi ini akan menampilkan data yang dipilih dari tabel `Gn_Biru` sesuai dengan ID, progres, dan mode yang ditentukan.
Baik, berikut adalah fungsi `display_selected_gugusan_nada` yang telah diperbarui untuk memenuhi ketentuan yang Anda berikan:
import sqlite3
def display_selected_gugusan_nada(progres, mode, id):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
c.execute("SELECT * FROM Gn_Biru")
records = c.fetchall()
conn.close()
selected_data = {}
# Naik Mode
if mode == "naik":
if id == 1:
if progres == 1:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[0][3], "Bass_2": records[0][4], "Trebel_2": records[0][5], "Bass_3": records[0][6] }
elif progres == 2:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[2][3], "Bass_2": records[0][4] }
elif progres == 3:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[1][3], "Bass_2": records[0][4], "Trebel_2": records[1][5] }
elif id == 2:
if progres == 1:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[1][3], "Bass_2": records[1][4], "Trebel_2": records[1][5] }
elif progres == 2:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[0][3], "Bass_2": records[1][4], "Trebel_2": records[0][5], "Bass_3": records[1][6] }
elif progres == 3:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[2][3], "Bass_2": records[1][4] }
elif id == 3:
if progres == 1:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[2][3], "Bass_2": records[2][4] }
elif progres == 2:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[1][3], "Bass_2": records[2][4], "Trebel_2": records[1][5] }
elif progres == 3:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[0][3], "Bass_2": records[2][4], "Trebel_2": records[0][5], "Bass_3": records[2][6] }
# Turun Mode
elif mode == "turun":
if id == 1:
if progres == 1:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[0][3], "Bass_2": records[0][4] }
elif progres == 2:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[1][3], "Bass_2": records[0][4], "Trebel_2": records[1][5] }
elif progres == 3:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[2][3], "Bass_2": records[0][4], "Trebel_2": records[2][5], "Bass_3": records[0][6] }
elif id == 2:
if progres == 1:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[1][3], "Bass_2": records[1][4], "Trebel_2": records[1][5] }
elif progres == 2:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[2][3], "Bass_2": records[1][4], "Trebel_2": records[2][5], "Bass_3": records[1][6] }
elif progres == 3:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[0][3], "Bass_2": records[1][4] }
elif id == 3:
if progres == 1:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[2][3], "Bass_2": records[2][4], "Trebel_2": records[2][5], "Bass_3": records[2][6] }
elif progres == 2:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[0][3], "Bass_2": records[2][4] }
elif progres == 3:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[1][3], "Bass_2": records[2][4] }
return selected_data
# Example usage
print(display_selected_gugusan_nada(1, "naik", 1))
print(display_selected_gugusan_nada(2, "turun", 2))
print(display_selected_gugusan_nada(3, "naik", 3))
Penjelasan:
1. Fungsi `display_selected_gugusan_nada` menerima tiga parameter: `progres`, `mode`, dan `id`.
2. Fungsi ini mengambil semua data dari tabel `Gn_Biru`.
3. Berdasarkan nilai `progres`, `mode`, dan `id`, fungsi ini memilih data yang sesuai dari tabel `Gn_Biru`.
4. Data yang dipilih disimpan dalam kamus `selected_data` yang kemudian dikembalikan oleh fungsi.
Silakan coba fungsi ini dan sesuaikan jika ada bagian yang perlu diperbaiki lebih lanjut.
Jika tombol sakelar__btn1, atau sakelar_btn2, atau sakelar_btn3 dipilih atau ditekan dan memilih mode Naik atau Turun, maka belum ada data yang tampil pada entryBox Gugusan Nada Terpiloh
Baik, saya akan memberikan solusi dengan memperbaiki fungsi `display_selected_gugusan_nada` dan menambahkan logika untuk memperbarui tampilan `entryBox` saat tombol `toggle_btn` ditekan. Berikut implementasinya:
1. Tambahkan fungsi untuk memperbarui `entryBox` dengan data yang dipilih.
2. Tambahkan pemanggilan fungsi ini pada event handler dari `toggle_btn`.
### Langkah-Langkah Implementasi
1. **Fungsi `update_entryboxes`:** Fungsi ini akan memperbarui `entryBox` dengan data yang dipilih.
2. **Event Handler:** Fungsi-fungsi event handler untuk tombol `toggle_btn` yang memanggil `update_entryboxes` setelah memanggil `display_selected_gugusan_nada`.
### Kode yang diperbarui
import sqlite3
from tkinter import Tk, Label, Entry, Button, Frame, StringVar
def display_selected_gugusan_nada(progres, mode, id):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
c.execute("SELECT * FROM Gn_Biru")
records = c.fetchall()
conn.close()
selected_data = {}
# Naik Mode
if mode == "naik":
if id == 1:
if progres == 1:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[0][3], "Bass_2": records[0][4], "Trebel_2": records[0][5], "Bass_3": records[0][6] }
elif progres == 2:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[2][3], "Bass_2": records[0][4] }
elif progres == 3:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[1][3], "Bass_2": records[0][4], "Trebel_2": records[1][5] }
elif id == 2:
if progres == 1:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[1][3], "Bass_2": records[1][4], "Trebel_2": records[1][5] }
elif progres == 2:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[0][3], "Bass_2": records[1][4], "Trebel_2": records[0][5], "Bass_3": records[1][6] }
elif progres == 3:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[2][3], "Bass_2": records[1][4] }
elif id == 3:
if progres == 1:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[2][3], "Bass_2": records[2][4] }
elif progres == 2:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[1][3], "Bass_2": records[2][4], "Trebel_2": records[1][5] }
elif progres == 3:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[0][3], "Bass_2": records[2][4], "Trebel_2": records[0][5], "Bass_3": records[2][6] }
# Turun Mode
elif mode == "turun":
if id == 1:
if progres == 1:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[0][3], "Bass_2": records[0][4] }
elif progres == 2:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[1][3], "Bass_2": records[0][4], "Trebel_2": records[1][5] }
elif progres == 3:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[2][3], "Bass_2": records[0][4], "Trebel_2": records[2][5], "Bass_3": records[0][6] }
elif id == 2:
if progres == 1:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[1][3], "Bass_2": records[1][4], "Trebel_2": records[1][5] }
elif progres == 2:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[2][3], "Bass_2": records[1][4], "Trebel_2": records[2][5], "Bass_3": records[1][6] }
elif progres == 3:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[0][3], "Bass_2": records[1][4] }
elif id == 3:
if progres == 1:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[2][3], "Bass_2": records[2][4], "Trebel_2": records[2][5], "Bass_3": records[2][6] }
elif progres == 2:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[0][3], "Bass_2": records[2][4] }
elif progres == 3:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[1][3], "Bass_2": records[2][4] }
return selected_data
def update_entryboxes(progres, mode, id):
data = display_selected_gugusan_nada(progres, mode, id)
for key, value in data.items():
entry_boxes[key].set(value)
def setup_naik_mode(progres):
toggle_btn1.config(command=lambda: update_entryboxes(progres, "naik", 1))
toggle_btn2.config(command=lambda: update_entryboxes(progres, "naik", 2))
toggle_btn3.config(command=lambda: update_entryboxes(progres, "naik", 3))
def setup_turun_mode(progres):
toggle_btn1.config(command=lambda: update_entryboxes(progres, "turun", 1))
toggle_btn2.config(command=lambda: update_entryboxes(progres, "turun", 2))
toggle_btn3.config(command=lambda: update_entryboxes(progres, "turun", 3))
# GUI Setup
root = Tk()
root.title("Gugusan Nada")
head_frame = Frame(root)
head_frame.pack()
option_frame = Frame(root)
option_frame.pack()
bottom_frame = Frame(root)
bottom_frame.pack()
# Labels
labels = ["Bass_1", "Trebel_1", "Bass_2", "Trebel_2", "Bass_3"]
entry_boxes = {}
for label in labels:
lbl = Label(bottom_frame, text=label)
lbl.pack()
entry_var = StringVar()
entry_box = Entry(bottom_frame, textvariable=entry_var)
entry_box.pack()
entry_boxes[label] = entry_var
# Buttons
toggle_btn1 = Button(head_frame, text="Toggle 1")
toggle_btn1.pack()
toggle_btn2 = Button(head_frame, text="Toggle 2")
toggle_btn2.pack()
toggle_btn3 = Button(head_frame, text="Toggle 3")
toggle_btn3.pack()
# Initial Setup
setup_naik_mode(1)
root.mainloop()
### Penjelasan:
1. **`display_selected_gugusan_nada`:** Fungsi ini mengambil data dari database sesuai dengan ketentuan yang telah Anda berikan.
2. **`update_entryboxes`:** Fungsi ini akan memperbarui nilai pada `entryBox` dengan data yang dipilih dari `display_selected_gugusan_nada`.
3. **Event Handlers:** Tombol `toggle_btn` sekarang memanggil `update_entryboxes` dengan parameter yang sesuai, memperbarui `entryBox` dengan data yang dipilih saat tombol ditekan.
Anda dapat mencoba kode ini dan menyesuaikannya jika diperlukan untuk memastikan bahwa data ditampilkan dengan benar pada `entryBox` saat tombol `toggle_btn` ditekan.
Karena terlalu banyak baris kodenya, akhirnya saya bagi dua kodenya menjadi dua file, yaitu file CRUD_Gn_Biru py dan file DATA_Gn_Biru.py.
Kode isi file DATA_Gn_Biru.py adalah berikut ini:
import tkinter as tk
from tkinter import ttk
import sqlite3
from tkinter import messagebox
# Initialize the main window
root = tk.Tk()
root.geometry("690x1390")
root.title("Arah Arus Musik Gn_Biru")
main_frame = tk.Frame(root)
main_frame.pack(fill=tk.BOTH, expand=1)
canvas = tk.Canvas(main_frame)
canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
scrollbar_y = ttk.Scrollbar(main_frame, orient=tk.VERTICAL, command=canvas.yview)
scrollbar_y.pack(side=tk.RIGHT, fill=tk.Y)
scrollbar_x = ttk.Scrollbar(root, orient=tk.HORIZONTAL, command=canvas.xview)
scrollbar_x.pack(side=tk.BOTTOM, fill=tk.X)
canvas.configure(yscrollcommand=scrollbar_y.set, xscrollcommand=scrollbar_x.set)
canvas.bind('<Configure>', lambda e: canvas.configure(scrollregion=canvas.bbox("all")))
content_frame = tk.Frame(canvas)
canvas.create_window((0, 0), window=content_frame, anchor="nw")
data_frame = tk.Frame(content_frame)
data_frame.grid(row=0, column=0, padx=10, pady=10)
def create_database():
conn = sqlite3.connect("DATAMUSIK.db")
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS Gn_Biru
(ID INTEGER PRIMARY KEY,
Level TEXT,
Bass_1 REAL,
Trebel_1 REAL,
Bass_2 REAL,
Trebel_2 REAL,
Bass_3 REAL)''')
conn.commit()
conn.close()
# Fungsi CRUD untuk Gn_Biru
def create_gn_biru_record(row):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
try:
c.execute("INSERT INTO Gn_Biru (ID, Level, Bass_1, Trebel_1, Bass_2, Trebel_2, Bass_3) VALUES (?, ?, ?, ?, ?, ?, ?)",
(row[0].get(), row[1].get(), row[2].get(), row[3].get(), row[4].get(), row[5].get(), row[6].get()))
conn.commit()
except Exception as e:
print(f"Error inserting record: {e}")
finally:
conn.close()
clear_entries_gn_biru(row)
display_records()
def read_gn_biru_record(row):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
try:
c.execute("SELECT * FROM Gn_Biru WHERE ID = ?", (row[0].get(),))
record = c.fetchone()
if record:
for col, value in enumerate(record):
row[col].delete(0, tk.END)
row[col].insert(0, int(value) if isinstance(value, float) else value)
else:
print(f"No record found for ID {row[0].get()}")
display_records()
except Exception as e:
print(f"Error reading record: {e}")
finally:
conn.close()
def update_gn_biru_record(row):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
try:
c.execute("UPDATE Gn_Biru SET Level = ?, Bass_1 = ?, Trebel_1 = ?, Bass_2 = ?, Trebel_2 = ?, Bass_3 = ? WHERE ID = ?",
(row[1].get(), row[2].get(), row[3].get(), row[4].get(), row[5].get(), row[6].get(), row[0].get()))
conn.commit()
except Exception as e:
print(f"Error updating record: {e}")
finally:
conn.close()
clear_entries_gn_biru(row)
display_records()
def delete_gn_biru_record(row):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
try:
c.execute("DELETE FROM Gn_Biru WHERE ID = ?", (row[0].get(),))
conn.commit()
except Exception as e:
print(f"Error deleting record: {e}")
finally:
conn.close()
clear_entries_gn_biru(row)
display_records()
def clear_entries_gn_biru(row=None):
if row:
for entry in row:
entry.delete(0, tk.END)
else:
for row in entry_rows:
for entry in row:
entry.delete(0, tk.END)
setup_default_mode()
input_id_entry()
def setup_default_mode():
levels = ["Satu", "Dua", "Tiga"]
for row_index, row in enumerate(entry_rows):
row[1].delete(0, tk.END)
row[1].insert(0, levels[row_index])
row[1].config(state='readonly')
def display_records():
for widget in record_frame.winfo_children():
widget.destroy()
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
c.execute("SELECT * FROM Gn_Biru")
records = c.fetchall()
conn.close()
for i, record in enumerate(records):
for j, value in enumerate(record):
tk.Label(record_frame, text=int(value) if isinstance(value, float) else value).grid(row=i, column=j, padx=5, pady=5)
#Label CRUD_Data
crud_data_label = tk.Label(data_frame, text="CRUD DATA Gn_Biru", bg="lightblue", fg="tomato")
crud_data_label.grid(row=0, column=0, sticky="w", padx=5, pady=5)
# Entry untuk Gn_Biru
labels = [" ID_ \n Gn_Biru", "Level", "Bass_1", "Trebel_1", "Bass_2", "Trebel_2", "Bass_3"]
for col_index, label in enumerate(labels):
tk.Label(data_frame, text=label).grid(row=1, column=col_index, padx=5, pady=5)
entry_rows = []
for i in range(3): # Create three rows of entries
row = []
for j in range(len(labels)):
if j == 0: # ID column
entry = tk.Entry(data_frame, width=4)
elif j == 1: # Level column
entry = tk.Entry(data_frame, width=6, bg="white", justify="center")
levels = ["Satu", "Dua", "Tiga"]
entry.insert(0, levels[i])
entry.config(state='readonly')
else:
entry = tk.Entry(data_frame, width=20)
entry.grid(row=i+2, column=j, padx=5, pady=5)
row.append(entry)
entry_rows.append(row)
# Tombol-tombol untuk CRUD
tk.Button(data_frame, text="Create", bg="blue", fg="yellow", command=lambda: create_gn_biru_record(get_current_row())).grid(row=7, column=2, padx=5, pady=5)
tk.Button(data_frame, text=" Read ", bg="blue", fg="yellow", command=lambda: read_gn_biru_record(get_current_row())).grid(row=7, column=3, padx=5, pady=5)
tk.Button(data_frame, text="Update", bg="blue", fg="yellow", command=lambda: update_gn_biru_record(get_current_row())).grid(row=7, column=4, padx=5, pady=5)
tk.Button(data_frame, text="Delete", bg="blue", fg="yellow", command=lambda: delete_gn_biru_record(get_current_row())).grid(row=7, column=5, padx=5, pady=5)
tk.Button(data_frame, text="Clear Entries", bg="lightblue", fg="yellow", command=lambda: clear_entries_gn_biru()).grid(row=7, column=6, padx=5, pady=5)
def get_current_row():
selected_id = id_entry.get()
for row in entry_rows:
if row[0].get() == selected_id:
return row
return entry_rows[0] # default to the first row if no match found
def input_id_entry():
# Dapatkan teks dari entry
input_id = id_entry.get()
# Bersihkan entry setelah input
id_entry.delete(0, tk.END)
# Menampilkan pesan konfirmasi
messagebox.showinfo("Info", "ID berhasil diinput dan dibersihkan")
id_label = tk.Label(data_frame, text="ID for \n Operation")
id_label.grid(row=5, column=0, padx=5, pady=5)
id_entry = tk.Entry(data_frame, width=6)
id_entry.grid(row=5, column=1, padx=5, pady=5)
# Membuat tombol input_id
input_id_button = tk.Button(data_frame, text="Clear ID", bg="red", fg="white", command=input_id_entry)
input_id_button.place(x=397, y=303)
# Frame untuk menampilkan records
record_frame = tk.Frame(content_frame)
record_frame.grid(row=9, column=0, sticky="w", padx=5, pady=10)
def open_crud_gn_biru_file():
filepath = "CRUD_Gn_Biru.py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
# Pilih Buttons
pilih_button = tk.Button(content_frame, text="Pilih Nada", command=open_crud_gn_biru_file, bg="green", fg="white")
pilih_button.grid(row=11, column=0, sticky="w", padx=395, pady=5)
# Inisialisasi database dan baca data awal
create_database()
setup_default_mode()
display_records()
root.mainloop()
Sedangkan kode isi file CRUD_Gn_Biru.py akan saya berikan di chat berikutnya ya
Baik, saya tunggu kode untuk file `CRUD_Gn_Biru.py`. Berikut adalah beberapa saran untuk file `DATA_Gn_Biru.py` agar lebih terstruktur:
1. **Pisahkan Fungsi-Fungsi**: Anda dapat membuat file terpisah untuk fungsi-fungsi database, sehingga file GUI Anda lebih bersih.
2. **Tambah Komentar**: Menambahkan komentar pada bagian-bagian penting agar mudah dipahami di masa mendatang.
3. **Penggunaan Fungsi `fetchall()`**: Pada fungsi `display_records`, pastikan hasil dari `fetchall()` diolah dengan benar agar tidak terjadi masalah ketika data yang diambil kosong atau tidak sesuai.
Setelah Anda mengirimkan kode untuk file `CRUD_Gn_Biru.py`, saya dapat membantu mengintegrasikan keduanya dan memberikan saran lebih lanjut jika diperlukan.
Berikut kode isi file CRUD_Gn_Biru.py:
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
import sqlite3
from tkinter import Tk, Label, Entry, Button, Frame, StringVar
import subprocess
import os
import logging
# Initialize logging
logging.basicConfig(level=logging.INFO)
# Function to initialize database
def init_db():
conn = sqlite3.connect("DATAMUSIK.db")
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS Gn_Biru
(ID INTEGER PRIMARY KEY,
Level TEXT,
Bass_1 REAL,
Trebel_1 REAL,
Bass_2 REAL,
Trebel_2 REAL,
Bass_3 REAL)''')
conn.commit()
conn.close()
# Initialize the main window
root = tk.Tk()
root.geometry("690x1390")
root.title("Arah Arus Musik")
# Head Frame
head_frame = tk.Frame(root, bg="#158aff", highlightbackground="white", highlightthickness=1)
head_frame.place()
# Content Frame
content_frame = tk.Frame(root)
content_frame.pack()
# Function to clear content frame
def clear_content_frame():
for widget in content_frame.winfo_children():
widget.destroy()
# CRUD Functions
def clear_entries():
for row in entry_rows:
for entry in row:
entry.delete(0, tk.END)
# Fungsi CRUD untuk Gn_Biru
def create_gn_biru_record(row):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
try:
c.execute("INSERT INTO Gn_Biru (ID, Level, Bass_1, Trebel_1, Bass_2, Trebel_2, Bass_3) VALUES (?, ?, ?, ?, ?, ?, ?)",
(row[0].get(), row[1].get(), row[2].get(), row[3].get(), row[4].get(), row[5].get(), row[6].get()))
conn.commit()
except Exception as e:
print(f"Error inserting record: {e}")
finally:
conn.close()
clear_entries_gn_biru(row)
display_records()
def read_gn_biru_record(row):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
try:
c.execute("SELECT * FROM Gn_Biru WHERE ID = ?", (row[0].get(),))
record = c.fetchone()
if record:
for col, value in enumerate(record):
row[col].delete(0, tk.END)
row[col].insert(0, int(value) if isinstance(value, float) else value)
else:
print(f"No record found for ID {row[0].get()}")
display_records()
except Exception as e:
print(f"Error reading record: {e}")
finally:
conn.close()
def update_gn_biru_record(row):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
try:
c.execute("UPDATE Gn_Biru SET Level = ?, Bass_1 = ?, Trebel_1 = ?, Bass_2 = ?, Trebel_2 = ?, Bass_3 = ? WHERE ID = ?",
(row[1].get(), row[2].get(), row[3].get(), row[4].get(), row[5].get(), row[6].get(), row[0].get()))
conn.commit()
except Exception as e:
print(f"Error updating record: {e}")
finally:
conn.close()
clear_entries_gn_biru(row)
display_records()
def delete_gn_biru_record(row):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
try:
c.execute("DELETE FROM Gn_Biru WHERE ID = ?", (row[0].get(),))
conn.commit()
except Exception as e:
print(f"Error deleting record: {e}")
finally:
conn.close()
clear_entries_gn_biru(row)
display_records()
def clear_entries_gn_biru(row=None):
if row:
for entry in row:
entry.delete(0, tk.END)
else:
for row in entry_rows:
for entry in row:
entry.delete(0, tk.END)
setup_default_mode()
input_id_entry()
def display_selected_gugusan_nada(progres, mode, id):
conn = sqlite3.connect('DATAMUSIK.db')
c = conn.cursor()
c.execute("SELECT * FROM Gn_Biru")
records = c.fetchall()
conn.close()
selected_data = {}
# Naik Mode
if mode == "naik":
if id == 1:
if progres == 1:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[0][3], "Bass_2": records[0][4], "Trebel_2": records[0][5], "Bass_3": records[0][6] }
elif progres == 2:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[2][3], "Bass_2": records[0][4] }
elif progres == 3:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[1][3], "Bass_2": records[0][4], "Trebel_2": records[1][5] }
elif id == 2:
if progres == 1:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[1][3], "Bass_2": records[1][4], "Trebel_2": records[1][5] }
elif progres == 2:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[0][3], "Bass_2": records[1][4], "Trebel_2": records[0][5], "Bass_3": records[1][6] }
elif progres == 3:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[2][3], "Bass_2": records[1][4] }
elif id == 3:
if progres == 1:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[2][3], "Bass_2": records[2][4] }
elif progres == 2:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[1][3], "Bass_2": records[2][4], "Trebel_2": records[1][5] }
elif progres == 3:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[0][3], "Bass_2": records[2][4], "Trebel_2": records[0][5], "Bass_3": records[2][6] }
# Turun Mode
elif mode == "turun":
if id == 1:
if progres == 1:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[0][3], "Bass_2": records[0][4] }
elif progres == 2:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[1][3], "Bass_2": records[0][4], "Trebel_2": records[1][5] }
elif progres == 3:
selected_data = { "Bass_1": records[0][2], "Trebel_1": records[2][3], "Bass_2": records[0][4], "Trebel_2": records[2][5], "Bass_3": records[0][6] }
elif id == 2:
if progres == 1:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[1][3], "Bass_2": records[1][4], "Trebel_2": records[1][5] }
elif progres == 2:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[2][3], "Bass_2": records[1][4], "Trebel_2": records[2][5], "Bass_3": records[1][6] }
elif progres == 3:
selected_data = { "Bass_1": records[1][2], "Trebel_1": records[0][3], "Bass_2": records[1][4] }
elif id == 3:
if progres == 1:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[2][3], "Bass_2": records[2][4], "Trebel_2": records[2][5], "Bass_3": records[2][6] }
elif progres == 2:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[0][3], "Bass_2": records[2][4] }
elif progres == 3:
selected_data = { "Bass_1": records[2][2], "Trebel_1": records[1][3], "Bass_2": records[2][4] }
return selected_data
# Example usage
print(display_selected_gugusan_nada(1, "naik", 1))
print(display_selected_gugusan_nada(2, "turun", 2))
print(display_selected_gugusan_nada(3, "naik", 3))
# Function to switch modes and update pages
def switch_mode(progres, mode):
if mode[progres - 1] == "naik":
mode[progres - 1] = "turun"
setup_turun_mode(progres)
else:
mode[progres - 1] = "naik"
setup_naik_mode(progres)
# Function to toggle menus
def toggle_menu(progres, mode):
if mode[progres - 1] == 'naik':
mode[progres - 1] = 'turun'
toggle_btns[progres - 1].config(text="X _ T")
pages[progres - 1] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']
indicator_labels[progres - 1].config(text="Turun")
else:
mode[progres - 1] = 'naik'
toggle_btns[progres - 1].config(text="☰ _ N")
pages[progres - 1] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_A_Bass']
indicator_labels[progres - 1].config(text="Naik")
display_pages(progres)
# Function to display pages
def display_pages(progres):
for widget in content_frame.winfo_children():
widget.destroy()
for page in pages[progres - 1]:
if page == 'Gn_Biru':
Gn_Biru_page()
elif page == 'Gn_Biru':
Gn_Biru_page()
update_buttons(progres)
# Function to setup "Naik" mode
def setup_naik_mode(progres):
if progres == 1:
pages[0] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_A_Bass']
elif progres == 2:
pages[1] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_A_Bass']
elif progres == 3:
pages[2] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_A_Bass']
display_pages(progres)
# Function to setup "Turun" mode
def setup_turun_mode(progres):
if progres == 1:
pages[0] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']
elif progres == 2:
pages[1] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']
elif progres == 3:
pages[2] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']
display_pages(progres)
# Current mode for each toggle button
current_mode = ['naik', 'naik', 'naik']
toggle_btns = []
indicator_labels = []
pages = [
['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_A_Bass'],
['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_A_Bass'],
['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_A_Bass']
]
# Toggle Button 1
toggle_btn1 = tk.Button(head_frame, text="☰ _ P 1", bg="#158aff", font=("bold", 6), fg="white", bd=0, activebackground="#158aff", activeforeground="white", command=lambda: toggle_menu(1, current_mode))
toggle_btn1.pack(side=tk.LEFT)
toggle_btn1.place(x=5, y=20)
toggle_btns.append(toggle_btn1)
title_lb1 = tk.Label(head_frame, text="Progres-1", bg="#158aff", fg="white", font=("bold", 7))
title_lb1.pack(side=tk.LEFT)
title_lb1.place(x=108, y=11)
indicator_label1 = tk.Label(head_frame, text="Turun", bg="#158aff", fg="yellow", font=("bold", 8))
indicator_label1.pack(side=tk.LEFT)
indicator_label1.place(x=127, y=55)
indicator_labels.append(indicator_label1)
# Toggle Button 2
toggle_btn2 = tk.Button(head_frame, text="☰ _ P 2", bg="#158aff", font=("bold", 6), fg="white", bd=0, activebackground="#158aff", activeforeground="white", command=lambda: toggle_menu(2, current_mode))
toggle_btn2.pack(side=tk.LEFT)
toggle_btn2.place(x=232, y=20)
toggle_btns.append(toggle_btn2)
title_lb2 = tk.Label(head_frame, text="Progres-2", bg="#158aff", fg="white", font=("bold", 7))
title_lb2.pack(side=tk.LEFT)
title_lb2.place(x=334, y=5)
indicator_label2 = tk.Label(head_frame, text="Turun", bg="#158aff", fg="yellow", font=("bold", 8))
indicator_label2.pack(side=tk.LEFT)
indicator_label2.place(x=368, y=55)
indicator_labels.append(indicator_label2)
# Toggle Button 3
toggle_btn3 = tk.Button(head_frame, text="☰ _ P 3", bg="#158aff", font=("bold", 6), fg="white", bd=0, activebackground="#158aff", activeforeground="white", command=lambda: toggle_menu(3, current_mode))
toggle_btn3.pack(side=tk.LEFT)
toggle_btn3.place(x=460, y=20)
toggle_btns.append(toggle_btn3)
title_lb3 = tk.Label(head_frame, text="Progres-3", bg="#158aff", fg="white", font=("bold", 7))
title_lb3.pack(side=tk.LEFT)
title_lb3.place(x=565, y=5)
indicator_label3 = tk.Label(head_frame, text="Turun", bg="#158aff", fg="yellow", font=("bold", 8))
indicator_label3.pack(side=tk.LEFT)
indicator_label3.place(x=599, y=55)
indicator_labels.append(indicator_label3)
head_frame.pack(side=tk.TOP, fill=tk.X)
head_frame.pack_propagate(False)
head_frame.configure(height=120)
# Options Frame
options_frame = tk.Frame(root, bg="#c3c3c3")
# Function to display Gn_A_Trebel page
def Gn_A_Trebel_page():
clear_content_frame()
tk.Label(content_frame, text="Ini adalah halaman Gn_A_Trebel", font=("Helvetica", 10)).pack()
# Function to display Gn_Biru page
def Gn_Biru_page():
clear_content_frame()
tk.Label(content_frame, text="Ini adalah halaman Gn_Biru", font=("Helvetica", 10)).pack()
# Function to display Gn_Cyan_Bawah page
def Gn_Cyan_Bawah_page():
clear_content_frame()
tk.Label(content_frame, text="Ini adalah halaman Gn_Cyan_Bawah", font=("Helvetica", 10)).pack()
# Function to display Gn_Cyan_Atas page
def Gn_Cyan_Atas_page():
clear_content_frame()
tk.Label(content_frame, text="Ini adalah halaman Gn_Cyan_Atas", font=("Helvetica", 10)).pack()
# Function to display Gn_Biru page
def Gn_A_Bass_page():
clear_content_frame()
tk.Label(content_frame, text="Ini adalah halaman Gn_A_Bass", font=("Helvetica", 10)).pack()
# Fungsi untuk membuka file CRUD_Gn_Biru.py
active_page = None # Menyimpan halaman aktif
# Fungsi untuk menjalankan file CRUD_Gn_A_Trebel.py, CRUD_Gn_Biru.py, CRUD_Gn_Cyan_Bawah.py, CRUD_Gn_Cysn_Atas.py, dan CRUD_Gn_A_Bass.py
def run_gn_a_trebel_file():
filepath = "CRUD_Gn_A_Trebel.py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
def run_gn_biru_file():
filepath = "CRUD_Gn_Biru.py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
def run_gn_cyan_bawah_file():
filepath = "CRUD_Gn_Cyan_Bawah(gabung).py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
def run_gn_cyan_atas_file():
filepath = "CRUD_Gn_Cyan_Atas(gabung).py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
def run_gn_a_bass_file():
filepath = "CRUD_Gn_A_Bass.py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
#Fungsi tombol di options_frame
Gn_A_Trebel_btn = tk.Button(options_frame, text="Gn_A_Trebel", font=("bold", 6), fg="yellow", bd=0, bg="grey", command=run_gn_a_trebel_file)
Gn_A_Trebel_btn.place(x=3, y=50)
Gn_A_Trebel_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")
Gn_A_Trebel_indicate.place(x=2, y=55, width=5, height=45)
Gn_Biru_btn = tk.Button(options_frame, text="Gn_Biru", font=("bold", 7), fg="yellow", bd=0, bg="blue", command=run_gn_biru_file)
Gn_Biru_btn.place(x=3, y=100)
Gn_Biru_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")
Gn_Biru_indicate.place(x=2, y=105, width=5, height=45)
Gn_Cyan_Bawah_btn = tk.Button(options_frame, text="Gn_Cyan_Bawah", font=("bold", 5), fg="yellow", bd=0, bg="green", command=run_gn_cyan_bawah_file)
Gn_Cyan_Bawah_btn.place(x=3, y=150)
Gn_Cyan_Bawah_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")
Gn_Cyan_Bawah_indicate.place(x=2, y=155, width=5, height=45)
Gn_Cyan_Atas_btn = tk.Button(options_frame, text="Gn_Cyan_Atas", font=("bold", 5), fg="yellow", bd=0, bg="green", command=run_gn_cyan_atas_file)
Gn_Cyan_Atas_btn.place(x=3, y=200)
Gn_Cyan_Atas_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")
Gn_Cyan_Atas_indicate.place(x=2, y=205, width=5, height=45)
Gn_A_Bass_btn = tk.Button(options_frame, text="Gn_A_Bass", font=("bold", 7), fg="yellow", bd=0, bg="grey", command=run_gn_a_bass_file)
Gn_A_Bass_btn.place(x=3, y=250)
Gn_A_Bass_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")
Gn_A_Bass_indicate.place(x=2, y=255, width=5, height=45)
options_frame.pack(side=tk.LEFT)
options_frame.pack_propagate(False)
options_frame.configure(width=170, height=300)
# Fungsi untuk membuka file CRUD_Gn_Cyan_Atas.py
active_page = None # Menyimpan halaman aktif
def open_crud_gn_cyan_atas():
filepath = "CRUD_Gn_Cyan_Atas(gabung).py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
def open_crud_gn_cyan_bawah():
# Implementasikan logika yang sama untuk halaman lain jika perlu
pass
def clear_content_frame(frame):
for widget in frame.winfo_children():
widget.destroy()
def indicate(page, frame):
global active_page
active_page = page
clear_content_frame(frame)
if page == "Gn_Biru":
open_crud_gn_biru()
elif page == "Gn_Cyan_Atas":
open_crud_gn_cyan_atas()
# Tambahkan logika untuk halaman lainnya jika diperlukan
def clear_indicators():
# Implementasikan logika jika ada indikator yang perlu di-reset
pass
# Function to display Gn_Biru page with CRUD operations
def display_crud_gn_biru_page():
tk.Label(bottom_frame, text=" Halaman CRUD_Gn_Biru \n", font=("Helvetica", 10), fg="tomato").pack()
# Buttons for CRUD operations
button_frame = tk.Frame(root)
button_frame.pack()
def go_to_crud_page():
for widget in bottom_frame.winfo_children():
widget.destroy()
display_crud_gn_biru_page()
display_selected_gugusan_nada(1, current_mode) # Update selected gugusan nada after toggling menu
# Bottom Frame
bottom_frame = tk.Frame(root, bg="#e2e2e2")
bottom_frame.pack(side=tk.TOP, fill=tk.X)
# Function to clear content frame
def clear_content_frame():
for widget in content_frame.winfo_children():
widget.destroy()
# CRUD Functions
def clear_entries():
for row in entry_rows:
for entry in row:
entry.delete(0, tk.END)
def open_dats_gn_biru_file():
filepath = "DATA_Gn_Biru.py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
# CRUD Buttons
crud_btn = tk.Button(bottom_frame, text="DATA", command=open_dats_gn_biru_file, bg="lightgreen", fg="blue")
crud_btn.grid(row=4, column=0, padx=10, pady=5)
separator = ttk.Separator(bottom_frame, orient='horizontal')
separator.grid(row=5, column=0, sticky="ew", pady=5)
# Fungsi untuk Naik ke Gn_Cyan_Atas (file CRUD_Gn_Cyan_Atas(gabung).py, atau Turum ke Gn_Cyan_Bawah (file CRUD_Gn_Cyan_Bawah(gabung).py)
active_page = None # Menyimpan halaman aktif
def next_to_crud_gn_cyan_atas():
filepath = "CRUD_Gn_Cyan_Atas(gabung).py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
def next_to_crud_gn_cyan_bawah():
filepath = "CRUD_Gn_Cyan_Bawah(gabung).py"
try:
with open(filepath, 'r') as file:
exec(file.read(), globals())
messagebox.showinfo("Success", "File executed successfully")
except Exception as e:
messagebox.showerror("Error", f"Failed to execute file: {e}")
prev_btn = tk.Button(bottom_frame, text="< Prev", command=None, bg="orange", fg="white") prev_btn.grid(row=6, column=0, padx=10, pady=5)naik_btn = tk.Button(bottom_frame, text=" Naik Lagi > ", command=next_to_crud_gn_cyan_atas, bg="orange", fg="white") naik_btn.grid(row=6, column=1, padx=10, pady=5)turun_btn = tk.Button(bottom_frame, text="Turun Lagi >", command=next_to_crud_gn_cyan_bawah, bg="orange", fg="white") turun_btn.grid(row=7, column=1, padx=10, pady=5)#Gugusan Nada Terpilih: "Gn_Biru" Terpilih gugusan_label = tk.Label(bottom_frame, text="Gn_Biru", fg="tomato") gugusan_label.grid(row=0, column=0, padx=10, pady=5)id_label = tk.Label(bottom_frame, text="ID from\nOperation") id_label.grid(row=1, column=0, padx=5, pady=5) id_entry = tk.Entry(bottom_frame, width=6) id_entry.place(x=180, y=75)Gugusan Nada Terpilih FieldGn_tetpilih_label = tk.Label(bottom_frame, text="Gugusan- \n Nada Terpilih:") Gn_tetpilih_label.grid(row=2, column=0, padx=5, pady=5)gugusan_nada_bass_1_entry = tk.Entry(bottom_frame, bg="white") gugusan_nada_bass_1_entry.grid(row=2, column=1, padx=5, pady=5) gugusan_nada_trebel_1_entry = tk.Entry(bottom_frame, bg="white") gugusan_nada_trebel_1_entry.grid(row=2, column=2, padx=5, pady=5) gugusan_nada_bass_2_entry = tk.Entry(bottom_frame, bg="white") gugusan_nada_bass_2_entry.grid(row=2, column=3, padx=5, pady=5) gugusan_nada_trebel_2_entry = tk.Entry(bottom_frame, bg="white") gugusan_nada_trebel_2_entry.grid(row=2, column=4, padx=5, pady=5) gugusan_nada_bass_3_entry = tk.Entry(bottom_frame, bg="white") gugusan_nada_bass_3_entry.grid(row=2, column=5, padx=5, pady=5) #Fungsi Tombol Ambil Gugusan nada Teroilih copy_b1_btn = tk.Button(bottom_frame, text="Copy_B1", command=None, bg="lightgreen", fg="blue") copy_b1_btn.grid(row=3, column=1, padx=10, pady=5) copy_t1_btn = tk.Button(bottom_frame, text="Copy_T1", command=None, bg="lightgreen", fg="blue") copy_t1_btn.grid(row=3, column=2, padx=10, pady=5) copy_b2_btn = tk.Button(bottom_frame, text="Copy_B2", command=None, bg="lightgreen", fg="blue") copy_b2_btn.grid(row=3, column=3, padx=10, pady=5) copy_t2_btn = tk.Button(bottom_frame, text="Copy_T2", command=None, bg="lightgreen", fg="blue") copy_t2_btn.grid(row=3, column=4, padx=10, pady=5) copy_b3_btn = tk.Button(bottom_frame, text="Copy_B3", command=None, bg="lightgreen", fg="blue") copy_b3_btn.grid(row=3, column=5, padx=10, pady=5)Frame to display data from databaseRecord Framerecord_frame = tk.Frame(root) record_frame.pack()# Fungsi untuk membuka file CRUD_Gn_A_Bass.pyactive_page = None # Menyimpan halaman aktif def go_to_CRUD_Gn_Biru_file(): filepath = "CRUD_Gn_Biru.py" try: with open(filepath, 'r') as file: exec(file.read(), globals()) messagebox.showinfo("Success", "File executed successfully") except Exception as e: messagebox.showerror("Error", f"Failed to execute file: {e}")Function to toggle menusdef toggle_menu(progres, mode): if mode[progres - 1] == 'naik': mode[progres - 1] = 'turun' toggle_btns[progres - 1].config(text="X _ T") pages[progres - 1] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_A_Trebel'] indicator_labels[progres - 1].config(text="Turun") else: mode[progres - 1] = 'naik' toggle_btns[progres - 1].config(text="☰ _ N") pages[progres - 1] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_A_Bass'] indicator_labels[progres - 1].config(text="Naik ") display_pages(progres) display_selected_gugusan_nada(progres, mode) # Update selected gugusan nada after toggling menuFunction to clear content framedef clear_content_frame(): for widget in content_frame.winfo_children(): widget.destroy()Update button visibility and orderdef update_buttons(progres): if current_mode[progres - 1] == "naik": Gn_A_Trebel_btn.place(x=3, y=50) Gn_Biru_btn.place(x=3, y=100) Gn_Cyan_Atas_btn.place(x=3, y=150) Gn_A_Bass_btn.place(x=3, y=200) Gn_Cyan_Bawah_btn.place_forget() else: Gn_A_Bass_btn.place(x=3, y=50) Gn_Biru_btn.place(x=3, y=100) Gn_Cyan_Bawah_btn.place(x=3, y=150) Gn_A_Trebel_btn.place(x=3, y=200) Gn_Cyan_Atas_btn.place_forget()Gn_A_Trebel_indicate.place(x=2, y=Gn_A_Trebel_btn.winfo_y() + 5, width=5, height=45)
Gn_Biru_indicate.place(x=2, y=Gn_Biru_btn.winfo_y() + 5, width=5, height=45)
Gn_Cyan_Atas_indicate.place(x=2, y=Gn_Cyan_Atas_btn.winfo_y() + 5, width=5, height=45)
Gn_Cyan_Bawah_indicate.place(x=2, y=Gn_Cyan_Bawah_btn.winfo_y() + 5, width=5, height=45)
Gn_A_Bass_indicate.place(x=2, y=Gn_A_Bass_btn.winfo_y() + 5, width=5, height=45)Function to indicate which page is activedef indicate(indicate_label, page_function): clear_indicators() reset_indicators() indicate_label.config(bg="#158aff") page_function()Clear all indicatorsdef clear_indicators(): Gn_A_Trebel_indicate.config(bg="#c3c3c3") Gn_Biru_indicate.config(bg="#c3c3c3") Gn_Cyan_Atas_indicate.config(bg="#c3c3c3") Gn_Cyan_Bawah_indicate.config(bg="#c3c3c3") Gn_A_Bass_indicate.config(bg="#c3c3c3")def reset_indicators(): Gn_A_Trebel_indicate.config(bg="#c3c3c3") Gn_Biru_indicate.config(bg="#c3c3c3") Gn_Cyan_Bawah_indicate.config(bg="#c3c3c3") Gn_Cyan_Atas_indicate.config(bg="#c3c3c3") Gn_A_Bass_indicate.config(bg="#c3c3c3")Initialize databaseinit_db()Initialize the application with the first progress setupsetup_naik_mode(1)Start the main looproot.mainloop()
KETENTUAN GUGUSAN NADA TERPILIH DARI DATA DI TABEL Gn_Biru di DATAMUSIK.db (Bagian 2)
Komentar
Posting Komentar
This Message