Langsung ke konten utama

MRMBUKA FILE DI PYTHON DAN MENJALANKAN ISINYA DENGAN PERINTAH EXEC

MRMBUKA FILE DI PYTHON DAN MENJALANKAN ISINYA DENGAN PERINTAH EXEC (Part-1)


Untuk fungsi def open_crud_gn_a_trebel, disini adalah membuka file lalu melakukan CRUD (bukan membuka isi file atau menulis isi file). Jadi perintahnya harus kita ganti dengan cara lain yaitu seperti membuka file dengan perintah exec

Jika tujuan Anda adalah membuka file dan menjalankan isinya menggunakan `exec` untuk melakukan operasi CRUD, Anda bisa mendefinisikan sebuah fungsi yang memuat dan mengeksekusi isi file Python secara dinamis. Pastikan file tersebut berisi definisi fungsi atau perintah yang ingin dijalankan.


Berikut adalah contoh bagaimana Anda dapat mengimplementasikan ini:


1. **Buat file yang berisi kode Python untuk CRUD**:

   Misalnya, file `crud_operations.py` berisi:

   ```python

   def create_record():

       print("Create operation executed")


   def read_record():

       print("Read operation executed")


   def update_record():

       print("Update operation executed")


   def delete_record():

       print("Delete operation executed")

   ```


2. **Fungsi untuk membuka dan mengeksekusi isi file**:

   Berikut adalah cara bagaimana Anda dapat mendefinisikan fungsi `open_crud_gn_a_trebel` untuk membuka dan mengeksekusi isi file:

   ```python

   import tkinter as tk

   from tkinter import filedialog


   def open_crud_gn_a_trebel():

       filepath = filedialog.askopenfilename(title="Select CRUD file", filetypes=[("Python Files", "*.py")])

       if filepath:

           with open(filepath, 'r') as file:

               exec(file.read(), globals())

           print("File executed successfully")


   root = tk.Tk()

   root.title("Aplikasi Notasi Lagu")


   # Frame utama

   main_frame = tk.Frame(root)

   main_frame.pack(fill=tk.BOTH, expand=True)


   # Frame bagian bawah

   bottom_frame = tk.Frame(main_frame)

   bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)


   # Tombol untuk membuka dan menjalankan file CRUD

   open_file_btn = tk.Button(main_frame, text="Open CRUD File", command=open_crud_gn_a_trebel)

   open_file_btn.pack()


   # Label di bottom_frame

   tk.Label(bottom_frame, text="Instruksi merangkai nada lagu \n dalam notasi angka, \n dengan Nada Penjuru Lagu \n (NPL) yang terprogram", font=("Helvetica", 10)).pack(side=tk.TOP, padx=10, pady=45)


   # Konfigurasi dan jalankan aplikasi

   root.mainloop()

   ```


Dalam contoh ini:

- `open_crud_gn_a_trebel` menggunakan `filedialog` untuk memilih file Python yang berisi operasi CRUD.

- Isi file kemudian dibaca dan dieksekusi menggunakan `exec(file.read(), globals())`, yang akan membuat fungsi-fungsi dalam file tersebut tersedia untuk digunakan.


3. **Menjalankan fungsi CRUD**:

   Setelah file dieksekusi, Anda dapat memanggil fungsi CRUD sesuai kebutuhan:

   ```python

   def call_create():

       if 'create_record' in globals():

           create_record()

       else:

           print("Function create_record not found")


   create_btn = tk.Button(main_frame, text="Create Record", command=call_create)

   create_btn.pack()

   ```


Pastikan file yang dipilih berisi definisi fungsi yang sesuai untuk CRUD. Dengan pendekatan ini, Anda dapat menjalankan operasi CRUD secara dinamis berdasarkan isi file yang dipilih.


Pada fungsi ini: def open_crud_gn_a_trebel():

    filepath = filedialog.askopenfilename(title="Select CRUD file", filetypes=[("Python Files", "*.py")])

    if filepath:

        with open(filepath, 'r') as file:

            exec(file.read(), globals())

        print("File executed successfully")

 

Ketika kode dieksekusi, lalu tombol MULAI ditekan, maka tampilan Directory untuk memilih file. Tolong tambahkan fungsi pengguliran di sini agar mudah mencari sebuah file py dari sekian banyak file lainnya hingga dibagian terbawah 

Untuk menambahkan kemampuan pengguliran (scrolling) di dialog pemilihan file, Anda dapat menggunakan komponen Tkinter `ScrolledText` atau membuat dialog pemilihan file yang kustom. Namun, cara yang lebih sederhana dan umumnya digunakan adalah memanfaatkan fungsi bawaan dari Tkinter `filedialog` yang sudah menyediakan pengguliran secara default.


Jika Anda masih ingin menambahkan fungsi pengguliran secara eksplisit untuk lebih mengontrol tampilan, berikut adalah contoh bagaimana Anda bisa menggunakan `tkinter` untuk membuat dialog pemilihan file dengan pengguliran:


1. **Menggunakan `filedialog` Bawaan dengan Pengguliran:**


   Fungsi `filedialog.askopenfilename` secara otomatis mendukung pengguliran saat memilih file dari dialog yang muncul. Anda tidak perlu menambahkan pengguliran secara manual. Berikut adalah contoh penggunaannya dalam konteks aplikasi Anda:


   ```python

   import tkinter as tk

   from tkinter import filedialog

   from tkinter import messagebox


   def open_crud_gn_a_trebel():

       filepath = filedialog.askopenfilename(

           title="Select CRUD file",

           filetypes=[("Python Files", "*.py")]

       )

       if filepath:

           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}")


   root = tk.Tk()

   root.title("Aplikasi Notasi Lagu")


   # Frame utama

   main_frame = tk.Frame(root)

   main_frame.pack(fill=tk.BOTH, expand=True)


   # Frame bagian bawah

   bottom_frame = tk.Frame(main_frame)

   bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)


   # Tombol untuk membuka dan menjalankan file CRUD

   open_file_btn = tk.Button(main_frame, text="Open CRUD File", command=open_crud_gn_a_trebel)

   open_file_btn.pack()


   # Label di bottom_frame

   tk.Label(bottom_frame, text="Instruksi merangkai nada lagu \n dalam notasi angka, \n dengan Nada Penjuru Lagu \n (NPL) yang terprogram", font=("Helvetica", 10)).pack(side=tk.TOP, padx=10, pady=45)


   # Konfigurasi dan jalankan aplikasi

   root.mainloop()

   ```


2. **Membuat Dialog Kustom dengan Pengguliran:**


   Jika Anda ingin kontrol lebih lanjut atas tampilan dialog, Anda dapat membuat dialog pemilihan file kustom dengan komponen `Listbox` dan `Scrollbar`. Berikut adalah contoh cara membuat dialog kustom untuk memilih file dengan pengguliran:


   ```python

   import os

   import tkinter as tk

   from tkinter import messagebox, Toplevel, Listbox, Scrollbar


   def open_crud_gn_a_trebel():

       def select_file():

           selected = file_listbox.curselection()

           if selected:

               filepath = file_listbox.get(selected[0])

               try:

                   with open(filepath, 'r') as file:

                       exec(file.read(), globals())

                   messagebox.showinfo("Success", "File executed successfully")

                   dialog.destroy()

               except Exception as e:

                   messagebox.showerror("Error", f"Failed to execute file: {e}")


       dialog = Toplevel(root)

       dialog.title("Select CRUD file")


       scrollbar = Scrollbar(dialog)

       scrollbar.pack(side=tk.RIGHT, fill=tk.Y)


       file_listbox = Listbox(dialog, yscrollcommand=scrollbar.set)

       file_listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)


       scrollbar.config(command=file_listbox.yview)


       py_files = [f for f in os.listdir() if f.endswith('.py')]

       for file in py_files:

           file_listbox.insert(tk.END, file)


       select_btn = tk.Button(dialog, text="Select", command.select_file)

       select_btn.pack()


   root = tk.Tk()

   root.title("Aplikasi Notasi Lagu")


   # Frame utama

   main_frame = tk.Frame(root)

   main_frame.pack(fill=tk.BOTH, expand=True)


   # Frame bagian bawah

   bottom_frame = tk.Frame(main_frame)

   bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)


   # Tombol untuk membuka dan menjalankan file CRUD

   open_file_btn = tk.Button(main_frame, text="Open CRUD File", command=open_crud_gn_a_trebel)

   open_file_btn.pack()


   # Label di bottom_frame

   tk.Label(bottom_frame, text="Instruksi merangkai nada lagu \n dalam notasi angka, \n dengan Nada Penjuru Lagu \n (NPL) yang terprogram", font=("Helvetica", 10)).pack(side=tk.TOP, padx=10, pady=45)


   # Konfigurasi dan jalankan aplikasi

   root.mainloop()

   ```


Dalam pendekatan ini:

- Dialog kustom menggunakan `Listbox` untuk menampilkan daftar file `.py`.

- `Scrollbar` ditambahkan ke `Listbox` untuk memungkinkan pengguliran.

- File `.py` di direktori saat ini ditampilkan di `Listbox`.

- Pengguna dapat memilih file dari daftar dan menekan tombol "Select" untuk mengeksekusi file yang dipilih.


Pilih pendekatan yang sesuai dengan kebutuhan Anda. Pendekatan pertama lebih sederhana dan biasanya sudah mencakup semua kebutuhan dasar, termasuk pengguliran otomatis. Pendekatan kedua memberikan kontrol lebih lanjut atas tampilan dialog.


Bagaimana kalau perintah pada fungsi def open_crud_gn_a_trebel, disini tanpa dialog file atau tanpa menanyakan dulu memilih type file, tapi langsung saja membuka file CRUD_Gn_A_Trebel.py, tolong berikan kodenya agar maksud saya untuk langsung ketika tombol MULAI ditekan maka langsung terbuka file CRUD_Gn_A_Trebel.py

Untuk langsung membuka dan mengeksekusi file `CRUD_Gn_A_Trebel.py` tanpa dialog pemilihan file, Anda cukup mengarahkan fungsi `open_crud_gn_a_trebel` untuk langsung membuka dan mengeksekusi file tersebut. Berikut adalah kodenya:


```python

import tkinter as tk

from tkinter import messagebox


def open_crud_gn_a_trebel():

    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}")


root = tk.Tk()

root.title("Aplikasi Notasi Lagu")


# Frame utama

main_frame = tk.Frame(root)

main_frame.pack(fill=tk.BOTH, expand=True)


# Frame bagian bawah

bottom_frame = tk.Frame(main_frame)

bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)


# Tombol untuk membuka dan menjalankan file CRUD

open_file_btn = tk.Button(main_frame, text="Mulai", command=open_crud_gn_a_trebel)

open_file_btn.pack()


# Label di bottom_frame

tk.Label(bottom_frame, text="Instruksi merangkai nada lagu \n dalam notasi angka, \n dengan Nada Penjuru Lagu \n (NPL) yang terprogram", font=("Helvetica", 10)).pack(side=tk.TOP, padx=10, pady=45)


# Konfigurasi dan jalankan aplikasi

root.mainloop()

```


Penjelasan:

- Fungsi `open_crud_gn_a_trebel` langsung membuka dan mengeksekusi file `CRUD_Gn_A_Trebel.py`.

- Pesan `Success` akan ditampilkan jika file berhasil dieksekusi.

- Pesan `Error` akan ditampilkan jika terjadi kesalahan saat mengeksekusi file.


Dengan kode ini, ketika tombol "Mulai" ditekan, aplikasi akan langsung membuka dan mengeksekusi file `CRUD_Gn_A_Trebel.py` tanpa dialog pemilihan file.


Setelah terbuka file CRUD_Gn_A_Trebel.py, lalu melakukan CRUD dengan menginput sebuah data, lalu menekan tombol CRUD yang ada, maka applikasi kembali ke halaman dimana tombol MULAI berada, bagaimana perbaikan kode agar supaya ketika menginput data dan menekan tombol CRUD maka akan tetap berada di halaman CRUD tersebut tetap di halaman pertama CRUD_Gn_A_Trebel.py sebelum melakukan operasi CRUD lebih lanjut

Untuk memastikan bahwa aplikasi tetap berada di halaman CRUD setelah melakukan operasi CRUD, kita perlu memastikan bahwa alur eksekusi di dalam file `CRUD_Gn_A_Trebel.py` tidak menyebabkan aplikasi kembali ke halaman utama. Untuk ini, kita perlu memastikan beberapa hal:


1. Struktur dari `CRUD_Gn_A_Trebel.py` harus ditulis sedemikian rupa sehingga tidak menyebabkan aplikasi kembali ke halaman utama.

2. Setelah operasi CRUD, tampilan tetap berada di halaman CRUD tersebut.


Saya akan memberikan contoh bagaimana mengatur file utama dan file CRUD agar tetap berada di halaman CRUD setelah operasi CRUD.


### File Utama (main.py)

```python

import tkinter as tk

from tkinter import messagebox


def open_crud_gn_a_trebel():

    filepath = "CRUD_Gn_A_Trebel.py"

    try:

        with open(filepath, 'r') as file:

            exec(file.read(), globals())

    except Exception as e:

        messagebox.showerror("Error", f"Failed to execute file: {e}")


root = tk.Tk()

root.title("Aplikasi Notasi Lagu")


# Frame utama

main_frame = tk.Frame(root)

main_frame.pack(fill=tk.BOTH, expand=True)


# Frame bagian bawah

bottom_frame = tk.Frame(main_frame)

bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)


# Tombol untuk membuka dan menjalankan file CRUD

open_file_btn = tk.Button(main_frame, text="Mulai", command=open_crud_gn_a_trebel)

open_file_btn.pack()


# Label di bottom_frame

tk.Label(bottom_frame, text="Instruksi merangkai nada lagu \n dalam notasi angka, \n dengan Nada Penjuru Lagu \n (NPL) yang terprogram", font=("Helvetica", 10)).pack(side=tk.TOP, padx=10, pady=45)


# Konfigurasi dan jalankan aplikasi

root.mainloop()

```


### File CRUD (CRUD_Gn_A_Trebel.py)

```python

import tkinter as tk

from tkinter import messagebox


def perform_crud_operation():

    # Contoh operasi CRUD

    data = entry.get()

    if data:

        # Lakukan operasi CRUD di sini

        messagebox.showinfo("Info", f"Data '{data}' berhasil diproses")

    else:

        messagebox.showwarning("Warning", "Input data tidak boleh kosong")


def create_crud_interface():

    # Membuat jendela CRUD baru

    crud_window = tk.Toplevel()

    crud_window.title("CRUD Gn A Trebel")


    global entry

    entry = tk.Entry(crud_window)

    entry.pack(pady=10)


    crud_button = tk.Button(crud_window, text="CRUD", command=perform_crud_operation)

    crud_button.pack(pady=10)


    back_button = tk.Button(crud_window, text="Kembali", command=crud_window.destroy)

    back_button.pack(pady=10)


if __name__ == "__main__":

    create_crud_interface()

```


### Penjelasan

1. **File Utama (`main.py`)**:

   - Aplikasi utama memiliki tombol "Mulai" yang menjalankan fungsi `open_crud_gn_a_trebel`.

   - Fungsi `open_crud_gn_a_trebel` membaca dan mengeksekusi file `CRUD_Gn_A_Trebel.py`.


2. **File CRUD (`CRUD_Gn_A_Trebel.py`)**:

   - Fungsi `create_crud_interface` membuat jendela CRUD baru menggunakan `tk.Toplevel`, sehingga jendela CRUD terpisah dari jendela utama.

   - Fungsi `perform_crud_operation` melakukan operasi CRUD dan menampilkan pesan berdasarkan input.

   - Tombol "CRUD" menjalankan `perform_crud_operation`.

   - Tombol "Kembali" menutup jendela CRUD tanpa mempengaruhi jendela utama.


Dengan struktur ini, ketika operasi CRUD dilakukan, aplikasi tetap berada di halaman CRUD tersebut dan tidak kembali ke halaman utama.


Tolong implementasikan hal tersebut pada kode isi file Modul_Mode_Progres.py:

import tkinter as tk

from tkinter import ttk

from tkinter import messagebox

from tkinter import filedialog

import subprocess

import os

import logging


# Initialize logging

logging.basicConfig(level=logging.INFO)


# 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_A_Trebel':

            Gn_A_Trebel_page()

        elif page == 'Gn_Biru':

            Gn_Biru_page()

        elif page == 'Gn_Cyan_Bawah':

            Gn_Cyan_Bawah_page()

        elif page == 'Gn_Cyan_Atas':

            Gn_Cyan_Atas_page()

        elif page == 'Gn_A_Bass':

            Gn_A_Bass_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)


# 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()


# 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=5)

toggle_btns.append(toggle_btn1)


title_lb1 = tk.Label(head_frame, text="Progres-1", bg="#158aff", fg="white", font=("bold", 8))

title_lb1.pack(side=tk.LEFT)

title_lb1.place(x=132, y=11)


indicator_label1 = tk.Label(head_frame, text="Naik", bg="#158aff", fg="white", font=("bold", 8))

indicator_label1.pack(side=tk.LEFT)

indicator_label1.place(x=200, y=11)

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=7, y=60)

toggle_btns.append(toggle_btn2)


title_lb2 = tk.Label(head_frame, text="Progres-2", bg="#158aff", fg="white", font=("bold", 8))

title_lb2.pack(side=tk.LEFT)

title_lb2.place(x=133, y=67)


indicator_label2 = tk.Label(head_frame, text="Naik", bg="#158aff", fg="white", font=("bold", 8))

indicator_label2.pack(side=tk.LEFT)

indicator_label2.place(x=200, y=67)

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=335, y=35)

toggle_btns.append(toggle_btn3)


title_lb3 = tk.Label(head_frame, text="Progres-3", bg="#158aff", fg="white", font=("bold", 8))

title_lb3.pack(side=tk.LEFT)

title_lb3.place(x=465, y=40)


indicator_label3 = tk.Label(head_frame, text="Naik", bg="#158aff", fg="white", font=("bold", 8))

indicator_label3.pack(side=tk.LEFT)

indicator_label3.place(x=530, y=40)

indicator_labels.append(indicator_label3)


head_frame.pack(side=tk.TOP, fill=tk.X)

head_frame.pack_propagate(False)

head_frame.configure(height=120)


# 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_A_Bass page

def Gn_A_Bass_page():

    clear_content_frame()

    tk.Label(content_frame, text="Ini adalah halaman Gn_A_Bass", font=("Helvetica", 10)).pack()



# Options Frame

options_frame = tk.Frame(root, bg="#c3c3c3")


Gn_A_Trebel_btn = tk.Button(options_frame, text="Gn_A_Trebel", font=("bold", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_A_Trebel_indicate, Gn_A_Trebel_page))

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="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Biru_indicate, Gn_Biru_page))

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", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Cyan_Bawah_indicate, Gn_Cyan_Bawah_page))

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", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Cyan_Atas_indicate, Gn_Cyan_Atas_page))

Gn_Cyan_Atas_btn.place(x=3, y=150)


Gn_Cyan_Atas_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")

Gn_Cyan_Atas_indicate.place(x=2, y=155, width=5, height=45)


Gn_A_Bass_btn = tk.Button(options_frame, text="Gn_A_Bass", font=("bold", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_A_Bass_indicate, Gn_A_Bass_page))

Gn_A_Bass_btn.place(x=3, y=200)


Gn_A_Bass_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")

Gn_A_Bass_indicate.place(x=2, y=205, width=5, height=45)


options_frame.pack(side=tk.LEFT)

options_frame.pack_propagate(False)

options_frame.configure(width=153, height=300)


# Main Frame

main_frame = tk.Frame(root, bg="#e2e2e2")



# Additional Frame for Labels and Buttons

bottom_frame = tk.Frame(root, bg="#e2e2e2")

bottom_frame.pack(side=tk.TOP, fill=tk.X)


# Fungsi untuk membuka file CRUD_Gn_A_Trebel.py 

def open_crud_gn_a_trebel():

    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}")

  

# Frame bagian bawah      

# Labels and Buttons in Bottom Frame

tk.Label(bottom_frame, text= "Instruksi merangkai nada lagu \n dalam notasi angka, \n dengan Nada Penjuru Lagu \n (NPL) yang terprogram", font=("Helvetica", 10)).pack(side=tk.TOP, padx=10, pady=45)

tk.Label(bottom_frame, text="Progres Gugisan nada (Gn) \n ada di Progres-1, \n atau Progres-2, atau Progres-3 \n pada arah arus musik \n di mode Naik atau Turun", font=("Helvetica", 9)).pack(side=tk.TOP, padx=10, pady=10)

tk.Label(bottom_frame, text="Arah arus musik (mode) Naik, \n dimulai dari Gn_A_Trebel, \n ke Gn_Biru, ke Gn_Cyan_Atas, \n ke Gn_A_Bass. \n Arah arus musik (mode) Turun, \n dimulai dari Gn_A_Bass \n ke Gn_Biru, ke Gn_Cyan_Bawah, \n ke Gn_A_Trebel.", font=("Helvetica", 9)).pack(side=tk.TOP, padx=10, pady=8)


tk.Button(bottom_frame, text="Tombol 1", command=lambda: print("Tombol 1 diklik", bg="green", fg="white")).pack(side=tk.LEFT, padx=10, pady=105)

tk.Button(bottom_frame, text="MULAI", command=open_crud_gn_a_trebel, bg="green", fg="white").pack(side=tk.RIGHT, padx=10, pady=105)

 


# Function to clear content frame

def clear_content_frame():

    for widget in content_frame.winfo_children():

        widget.destroy()


# Update button visibility and order

def 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 active

def indicate(indicate_label, page_function):

    clear_indicators()

    reset_indicators()

    indicate_label.config(bg="#158aff")

    page_function()


# Clear all indicators

def 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 the application with the first progress setup

setup_naik_mode(1)


# Start the main loop

root.mainloop()



Dan kode isi file CRUD_Gn_A_Trebel.py:

import tkinter as tk

from tkinter import ttk, messagebox

import sqlite3


# Function to initialize database

def init_db():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute('''CREATE TABLE IF NOT EXISTS Gn_A_Trebel (

                 id INTEGER PRIMARY KEY,

                 Level TEXT NOT NULL,

                 Gugusan_nada INT NOT NULL)''')

    conn.commit()

    conn.close()


# Function to clear content frame

def clear_content_frame():

    for widget in content_frame.winfo_children():

        widget.destroy()


# CRUD Functions

def clear_entries():

    id_entry.delete(0, tk.END)

    level_entry.delete(0, tk.END)

    gugusan_nada_entry.delete(0, tk.END)


def create_record():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("INSERT INTO Gn_A_Trebel (Level, Gugusan_nada) VALUES (?, ?)",

              (level_entry.get(), gugusan_nada_entry.get()))

    conn.commit()

    conn.close()

    messagebox.showinfo("Info", "Record Created Successfully")

    clear_entries()

    read_records()


def read_records():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("SELECT * FROM Gn_A_Trebel")

    records = c.fetchall()

    conn.close()

    display_data(records)


def update_record():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("UPDATE Gn_A_Trebel SET Level = ?, Gugusan_nada = ? WHERE id = ?",

              (level_entry.get(), gugusan_nada_entry.get(), id_entry.get()))

    conn.commit()

    conn.close()

    messagebox.showinfo("Info", "Record Updated Successfully")

    clear_entries()

    read_records()


def delete_record():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("DELETE FROM Gn_A_Trebel WHERE id = ?", (id_entry.get(),))

    conn.commit()

    conn.close()

    messagebox.showinfo("Info", "Record Deleted Successfully")

    clear_entries()

    read_records()


def display_data(data):

    for widget in data_frame.winfo_children():

        widget.destroy()

    for row in data:

        tk.Label(data_frame, text=row).pack()

        

# Function to display selected gugusan nada in the EntryBox

def display_selected_gugusan_nada(progres, mode):

    selected_id = 0

    if mode[progres - 1] == 'naik':

        if progres == 1:

            selected_id = 1

        elif progres == 2:

            selected_id = 2

        elif progres == 3:

            selected_id = 3

    elif mode[progres - 1] == 'turun':

        if progres == 1:

            selected_id = 1

        elif progres == 2:

            selected_id = 3

        elif progres == 3:

            selected_id = 2

    

    # Retrieve the corresponding gugusan nada from database based on selected_id

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("SELECT Gugusan_nada FROM Gn_A_Trebel WHERE id = ?", (selected_id,))

    result = c.fetchone()

    conn.close()

    

    if result:

        gugusan_nada_entry.delete(0, tk.END)

        gugusan_nada_entry.insert(0, result[0])

        

def go_to_crud_page():

    for widget in content_frame.winfo_children():

        widget.destroy()

    

    display_crud_gn_a_trebel_page() 

    

    display_selected_gugusan_nada(1, current_mode) # Update selected gugusan nada after toggling menu  

    

# 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_Atas', '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_Bawah', '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 menu


# 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_A_Trebel':

            Gn_A_Trebel_page()

        elif page == 'Gn_Biru':

            Gn_Biru_page()

        elif page == 'Gn_Cyan_Bawah':

            Gn_Cyan_Bawah_page()

        elif page == 'Gn_Cyan_Atas':

            Gn_Cyan_Atas_page()

        elif page == 'Gn_A_Bass':

            Gn_A_Bass_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_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass']

    elif progres == 2:

        pages[1] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass']

    elif progres == 3:

        pages[2] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', '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_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']

    elif progres == 2:

        pages[1] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']

    elif progres == 3:

        pages[2] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']

    display_pages(progres)


# Function to update buttons (this was missing)

def update_buttons(progres):

    y_position = 50

    for page in pages[progres - 1]:

        if page == 'Gn_A_Trebel':

            Gn_A_Trebel_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Biru':

            Gn_Biru_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Cyan_Bawah':

            Gn_Cyan_Bawah_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Cyan_Atas':

            Gn_Cyan_Atas_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_A_Bass':

            Gn_A_Bass_btn.place(x=3, y=y_position)

            y_position += 50


# 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()


# Current mode for each toggle button

current_mode = ['naik', 'naik', 'naik']

toggle_btns = []

indicator_labels = []

pages = [

    ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass'],

    ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass'],

    ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass']

]


current_mode = ['turun', 'turun', 'turun']

toggle_btns = []

indicator_labels = []

pages = [

    ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel'],

    ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel'],

    ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']

]


# 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="Naik ", 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="Naik ", 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="Naik ", 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="#158aff")


# Menu Buttons

Gn_A_Trebel_btn = tk.Button(options_frame, text="Gn_A_Trebel", font=("bold", 5), fg="white", bd=0, bg="#158aff", command=lambda: Gn_A_Trebel_page())

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", 6), fg="white", bd=0, bg="#158aff", command=lambda: Gn_Biru_page())

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="white", bd=0, bg="#158aff", command=lambda: Gn_Cyan_Bawah_page())

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="white", bd=0, bg="#158aff", command=lambda: Gn_Cyan_Atas_page())

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", 6), fg="white", bd=0, bg="#158aff", command=lambda: Gn_A_Bass_page())

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=153, height=1215)


# Main Frame

main_frame = tk.Frame(root, bg="#e2e2e2")


# Function to update buttons based on current mode

def update_buttons(progres):

    y_position = 50

    for page in pages[progres - 1]:

        if page == 'Gn_A_Trebel':

            Gn_A_Trebel_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Biru':

            Gn_Biru_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Cyan':

            Gn_Cyan_Bawah_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Cyan':

            Gn_Cyan_Atas_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_A_Bass':

            Gn_A_Bass_btn.place(x=3, y=y_position)

            y_position += 50


# Function to indicate active page

def indicate(indic, page_function):

    hide_indicators()

    indic.config(bg="#158aff")

    delete_pages()

    clear_content_frame()

    page_function()

    indic.config(bg="red")

    

 # Function to hide all indicators

def hide_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")

    

# Function to clear content frame

def clear_content_frame():

    for widget in content_frame.winfo_children():

        widget.destroy()      

             

# Function to display Gn_A_Trebel page

def Gn_A_Trebel_page():

    indicate(Gn_A_Trebel_indicate, lambda: 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():

    indicate(Gn_Biru_indicate, lambda: 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():

    indicate(Gn_Cyan_Bawah_indicate, lambda: 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():

    indicate(Gn_Cyan_Atas_indicate, lambda: tk.Label(content_frame, text="Ini adalah halaman Gn_Cyan_Atas", font=("Helvetica", 10)).pack())


# Function to display Gn_A_Bass page

def Gn_A_Bass_page():

    indicate(Gn_A_Bass_indicate, lambda: tk.Label(content_frame, text="Ini adalah halaman Gn_A_Bass", font=("Helvetica", 10)).pack())


# Labels and Entry boxes for database fields

    global id_entry, level_entry, gugusan_nada_entry, data_frame


    id_label = tk.Label(content_frame, text="ID:")

    id_label.pack()

    id_entry = tk.Entry(content_frame)

    id_entry.pack()


    level_label = tk.Label(content_frame, text="Level:")

    level_label.pack()

    level_entry = tk.Entry(content_frame)

    level_entry.pack()


    gugusan_nada_label = tk.Label(content_frame, text="Gugusan Nada:")

    gugusan_nada_label.pack()

    gugusan_nada_entry = tk.Entry(content_frame)

    gugusan_nada_entry.pack()


# Buttons for CRUD operations

    create_button = tk.Button(content_frame, text="Create", command=create_record, bg="green")

    create_button.pack()

    read_button = tk.Button(content_frame, text="Read", command=read_records, bg="green")

    read_button.pack()

    update_button = tk.Button(content_frame, text="Update", command=update_record, bg="green")

    update_button.pack()

    delete_button = tk.Button(content_frame, text="Delete", command=delete_record, bg="green")

    delete_button.pack()


# Frame to display data from database

    data_frame = tk.Frame(content_frame)

    data_frame.pack()


    read_records()

    

head_frame.config(height=100)


# Option Frame

option_frame = tk.Frame(root)

option_frame.pack()


# Label Gugusan Nada "Gn_A_Trebel" Terpilih 

gugusan_label = tk.Label(option_frame, text="Nada Gn_A_Trebel")

gugusan_label.grid(row=0, column=0, padx=10, pady=5)

# Gugusan Nada Terpilih Field

gugusan_label = tk.Label(option_frame, text="Gugusan- \n Nada Terpilih")

gugusan_label.grid(row=1, column=0, padx=10, pady=5)


gugusan_nada_entry = tk.Entry(option_frame, bg="white")

gugusan_nada_entry.grid(row=1, column=1, padx=10, pady=5)


# CRUD Buttons

crud_btn = tk.Button(option_frame, text="DATA", command=go_to_crud_page, bg="lightgreen", fg="blue")

crud_btn.grid(row=4, column=0, padx=10, pady=5)


copy_btn = tk.Button(option_frame, text="Copy", command=None, bg="lightgreen", fg="blue")

copy_btn.grid(row=4, column=1, padx=10, pady=5)


prev_btn = tk.Button(option_frame, text="< Prev", command=None, bg="orange", fg="white")

prev_btn.grid(row=5, column=0, padx=10, pady=5)


next_btn = tk.Button(option_frame, text="Next >", command=None, bg="orange", fg="white")

next_btn.grid(row=5, column=1, padx=10, pady=5)


# Data Frame

data_frame = tk.Frame(root)

data_frame.pack()


read_records()


# Function to display Gn_A_Trebel page with CRUD operations

def display_crud_gn_a_trebel_page():

    tk.Label(content_frame, text="Ini adalah halaman CRUD Gn_A_Trebel", font=("Helvetica", 10)).pack()


    global id_entry, level_entry, gugusan_nada_entry, data_frame


    id_label = tk.Label(content_frame, text="ID:")

    id_label.pack()

    id_entry = tk.Entry(content_frame)

    id_entry.pack()


    level_label = tk.Label(content_frame, text="Level:")

    level_label.pack()

    level_entry = tk.Entry(content_frame)

    level_entry.pack()


    gugusan_nada_label = tk.Label(content_frame, text="Gugusan Nada:")

    gugusan_nada_label.pack()

    gugusan_nada_entry = tk.Entry(content_frame)

    gugusan_nada_entry.pack()


    create_button = tk.Button(content_frame, text="Create", command=create_record)

    create_button.pack()

    read_button = tk.Button(content_frame, text="Read", command=read_records)

    read_button.pack()

    update_button = tk.Button(content_frame, text="Update", command=update_record)

    update_button.pack()

    delete_button = tk.Button(content_frame, text="Delete", command=delete_record)

    delete_button.pack()


    data_frame = tk.Frame(content_frame)

    data_frame.pack()


    read_records()


# 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_Atas', '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_Bawah', '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 menu

        

# Function to display Gn_A_Trebel page

def Gn_A_Trebel_page():

    indicate(Gn_A_Trebel_indicate, lambda: tk.Label(content_frame, text="Ini adalah halaman Gn_A_Trebel", font=("Helvetica", 10)).pack())

    

    display_selected_gugusan_nada(1, current_mode) # Display initially for progres-1

    

# Function to display selected gugusan nada in the EntryBox

def display_selected_gugusan_nada(progres, mode):

    selected_id = 0

    if mode[progres - 1] == 'naik':

        if progres == 1:

            selected_id = 1

        elif progres == 2:

            selected_id = 2

        elif progres == 3:

            selected_id = 3

    elif mode[progres - 1] == 'turun':

        if progres == 1:

            selected_id = 1

        elif progres == 2:

            selected_id = 3

        elif progres == 3:

            selected_id = 2

            

# Retrieve the corresponding gugusan nada from database based on selected_id

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("SELECT Gugusan_nada FROM Gn_A_Trebel WHERE id = ?", (selected_id,))

    result = c.fetchone()

    conn.close()

    

    if result:

        gugusan_nada_entry.delete(0, tk.END)

        gugusan_nada_entry.insert(0, result[0])

 

# Function to delete all pages

def delete_pages():

    for frame in main_frame.winfo_children():

        frame.destroy()

        

# Initialize and display default mode

def setup_default_mode(progres):

    display_pages(progres)

    


# Initialize database

init_db()


main_frame= tk.Frame(root, highlightbackground="black", highlightthickness= 1)

main_frame.pack(side=tk.LEFT)

main_frame.pack_propagate(False)

main_frame.configure(width=525, height=1205)


# Run the application

root.mainloop()


Berikut adalah implementasi lengkap kode isi file `CRUD_Gn_A_Trebel.py`:


```python

import tkinter as tk

from tkinter import ttk, messagebox

import sqlite3


# Function to initialize database

def init_db():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute('''CREATE TABLE IF NOT EXISTS Gn_A_Trebel (

                 id INTEGER PRIMARY KEY,

                 Level TEXT NOT NULL,

                 Gugusan_nada INT NOT NULL)''')

    conn.commit()

    conn.close()


# Function to clear content frame

def clear_content_frame():

    for widget in content_frame.winfo_children():

        widget.destroy()


# CRUD Functions

def clear_entries():

    id_entry.delete(0, tk.END)

    level_entry.delete(0, tk.END)

    gugusan_nada_entry.delete(0, tk.END)


def create_record():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("INSERT INTO Gn_A_Trebel (Level, Gugusan_nada) VALUES (?, ?)",

              (level_entry.get(), gugusan_nada_entry.get()))

    conn.commit()

    conn.close()

    messagebox.showinfo("Info", "Record Created Successfully")

    clear_entries()

    read_records()


def read_records():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("SELECT * FROM Gn_A_Trebel")

    records = c.fetchall()

    conn.close()

    display_data(records)


def update_record():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("UPDATE Gn_A_Trebel SET Level = ?, Gugusan_nada = ? WHERE id = ?",

              (level_entry.get(), gugusan_nada_entry.get(), id_entry.get()))

    conn.commit()

    conn.close()

    messagebox.showinfo("Info", "Record Updated Successfully")

    clear_entries()

    read_records()


def delete_record():

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("DELETE FROM Gn_A_Trebel WHERE id = ?", (id_entry.get(),))

    conn.commit()

    conn.close()

    messagebox.showinfo("Info", "Record Deleted Successfully")

    clear_entries()

    read_records()


def display_data(data):

    for widget in data_frame.winfo_children():

        widget.destroy()

    for row in data:

        tk.Label(data_frame, text=row).pack()


# Function to display selected gugusan nada in the EntryBox

def display_selected_gugusan_nada(progres, mode):

    selected_id = 0

    if mode[progres - 1] == 'naik':

        if progres == 1:

            selected_id = 1

        elif progres == 2:

            selected_id = 2

        elif progres == 3:

            selected_id = 3

    elif mode[progres - 1] == 'turun':

        if progres == 1:

            selected_id = 1

        elif progres == 2:

            selected_id = 3

        elif progres == 3:

            selected_id = 2


    # Retrieve the corresponding gugusan nada from database based on selected_id

    conn = sqlite3.connect('DATAMUSIK.db')

    c = conn.cursor()

    c.execute("SELECT Gugusan_nada FROM Gn_A_Trebel WHERE id = ?", (selected_id,))

    result = c.fetchone()

    conn.close()


    if result:

        gugusan_nada_entry.delete(0, tk.END)

        gugusan_nada_entry.insert(0, result[0])


def go_to_crud_page():

    clear_content_frame()

    display_crud_gn_a_trebel_page()

    display_selected_gugusan_nada(1, current_mode) # Update selected gugusan nada after toggling menu


# 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_Atas', '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_Bawah', '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 menu


# Function to display pages

def display_pages(progres):

    clear_content_frame()


    for page in pages[progres - 1]:

        if page == 'Gn_A_Trebel':

            Gn_A_Trebel_page()

        elif page == 'Gn_Biru':

            Gn_Biru_page()

        elif page == 'Gn_Cyan_Bawah':

            Gn_Cyan_Bawah_page()

        elif page == 'Gn_Cyan_Atas':

            Gn_Cyan_Atas_page()

        elif page == 'Gn_A_Bass':

            Gn_A_Bass_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_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass']

    elif progres == 2:

        pages[1] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass']

    elif progres == 3:

        pages[2] = ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', '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_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']

    elif progres == 2:

        pages[1] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']

    elif progres == 3:

        pages[2] = ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']

    display_pages(progres)


# Function to update buttons (this was missing)

def update_buttons(progres):

    y_position = 50

    for page in pages[progres - 1]:

        if page == 'Gn_A_Trebel':

            Gn_A_Trebel_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Biru':

            Gn_Biru_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Cyan_Bawah':

            Gn_Cyan_Bawah_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_Cyan_Atas':

            Gn_Cyan_Atas_btn.place(x=3, y=y_position)

            y_position += 50

        elif page == 'Gn_A_Bass':

            Gn_A_Bass_btn.place(x=3, y=y_position)

            y_position += 50


# 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()


# Current mode for each toggle button

current_mode = ['naik', 'naik', 'naik']

toggle_btns = []

indicator_labels = []

pages = [

    ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass'],

    ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass'],

    ['Gn_A_Trebel', 'Gn_Biru', 'Gn_Cyan_Bawah', 'Gn_Cyan_Atas', 'Gn_A_Bass']

]


current_mode = ['turun', 'turun', 'turun']

toggle_btns = []

indicator_labels = []

pages = [

    ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel'],

    ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel'],

    ['Gn_A_Bass', 'Gn_Biru', 'Gn_Cyan_Atas', 'Gn_Cyan_Bawah', 'Gn_A_Trebel']

]

# 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()


# 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=5)

toggle_btns.append(toggle_btn1)


title_lb1 = tk.Label(head_frame, text="Progres-1", bg="#158aff", fg="white", font=("bold", 8))

title_lb1.pack(side=tk.LEFT)

title_lb1.place(x=132, y=11)


indicator_label1 = tk.Label(head_frame, text="Turun", bg="#158aff", fg="white", font=("bold", 8))

indicator_label1.pack(side=tk.LEFT)

indicator_label1.place(x=200, y=11)

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=7, y=60)

toggle_btns.append(toggle_btn2)


title_lb2 = tk.Label(head_frame, text="Progres-2", bg="#158aff", fg="white", font=("bold", 8))

title_lb2.pack(side=tk.LEFT)

title_lb2.place(x=133, y=67)


indicator_label2 = tk.Label(head_frame, text="Naik", bg="#158aff", fg="white", font=("bold", 8))

indicator_label2.pack(side=tk.LEFT)

indicator_label2.place(x=200, y=67)

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=335, y=35)

toggle_btns.append(toggle_btn3)


title_lb3 = tk.Label(head_frame, text="Progres-3", bg="#158aff", fg="white", font=("bold", 8))

title_lb3.pack(side=tk.LEFT)

title_lb3.place(x=465, y=40)


indicator_label3 = tk.Label(head_frame, text="Naik", bg="#158aff", fg="white", font=("bold", 8))

indicator_label3.pack(side=tk.LEFT)

indicator_label3.place(x=530, y=40)

indicator_labels.append(indicator_label3)


head_frame.pack(side=tk.TOP, fill=tk.X)

head_frame.pack_propagate(False)

head_frame.configure(height=120)


# 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_A_Bass page

def Gn_A_Bass_page():

    clear_content_frame()

    tk.Label(content_frame, text="Ini adalah halaman Gn_A_Bass", font=("Helvetica", 10)).pack()


# Options Frame

options_frame = tk.Frame(root, bg="#c3c3c3")


Gn_A_Trebel_btn = tk.Button(options_frame, text="Gn_A_Trebel", font=("bold", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_A_Trebel_indicate, Gn_A_Trebel_page))

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="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Biru_indicate, Gn_Biru_page))

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", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Cyan_Bawah_indicate, Gn_Cyan_Bawah_page))

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", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Cyan_Atas_indicate, Gn_Cyan_Atas_page))

Gn_Cyan_Atas_btn.place(x=3, y=150)


Gn_Cyan_Atas_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")

Gn_Cyan_Atas_indicate.place(x=2, y=155, width=5, height=45)


Gn_A_Bass_btn = tk.Button(options_frame, text="Gn_A_Bass", font=("bold", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_A_Bass_indicate, Gn_A_Bass_page))

Gn_A_Bass_btn.place(x=3, y=200)


Gn_A_Bass_indicate = tk.Label(options_frame, text=" ", bg="#c3c3c3")

Gn_A_Bass_indicate.place(x=2, y=205, width=5, height=45)


options_frame.pack(side=tk.LEFT)

options_frame.pack_propagate(False)

options_frame.configure(width=153, height=300)


# Main Frame

main_frame = tk.Frame(root, bg="#e2e2e2")


# Additional Frame for Labels and Buttons

bottom_frame = tk.Frame(root, bg="#e2e2e2")

bottom_frame.pack(side=tk.TOP, fill=tk.X)


# Fungsi untuk membuka file CRUD_Gn_A_Trebel.py 

def open_crud_gn_a_trebel():

    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}")

  

# Labels and Buttons in Bottom Frame

tk.Label(bottom_frame, text= "Instruksi merangkai nada lagu \n dalam notasi angka, \n dengan Nada Penjuru Lagu \n (NPL) yang terprogram", font=("Helvetica", 10)).pack(side=tk.TOP, padx=10, pady=45)

tk.Label(bottom_frame, text="Progres Gugisan nada (Gn) \n ada di Progres-1, \n atau Progres-2, atau Progres-3 \n pada arah arus musik \n di mode Naik atau Turun", font=("Helvetica", 9)).pack(side=tk.TOP, padx=10, pady=10)

tk.Label(bottom_frame, text="Arah arus musik (mode) Naik, \n dimulai dari Gn_A_Trebel, \n ke Gn_Biru, ke Gn_Cyan_Atas, \n ke Gn_A_Bass. \n Arah arus musik (mode) Turun, \n dimulai dari Gn_A_Bass \n ke Gn_Biru, ke Gn_Cyan_Bawah, \n ke Gn_A_Trebel.", font=("Helvetica", 9)).pack(side=tk.TOP, padx=10, pady=8)


tk.Button(bottom_frame, text="Tombol 1", command=lambda: print("Tombol 1 diklik")).pack(side=tk.LEFT, padx=10, pady=105)

tk.Button(bottom_frame, text="MULAI", command=open_crud_gn_a_trebel, bg="green", fg="white").pack(side=tk.RIGHT, padx=10, pady=105)


bottom_frame.pack(side=tk.BOTTOM, fill=tk.X)


# 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_A_Bass page

def Gn_A_Bass_page():

    clear_content_frame()

    tk.Label(content_frame, text="Ini adalah halaman Gn_A_Bass", font=("Helvetica", 10)).pack()


# Options Frame

options_frame = tk.Frame(root, bg="#c3c3c3")


Gn_A_Trebel_btn = tk.Button(options_frame, text="Gn_A_Trebel", font=("bold", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_A_Trebel_indicate, Gn_A_Trebel_page))

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="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Biru_indicate, Gn_Biru_page))

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", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Cyan_Bawah_indicate, Gn_Cyan_Bawah_page))

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", 7), fg="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_Cyan_Atas_indicate, Gn_Cyan_Atas_page))

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="#158aff", bd=0, bg="#c3c3c3", command=lambda: indicate(Gn_A_Bass_indicate, Gn_A_Bass_page))

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=153, height=300)


# Main Frame

main_frame = tk.Frame(root, bg="#e2e2e2")


# Function to clear content frame

def clear_content_frame():

    for widget in content_frame.winfo_children():

        widget.destroy()


# Update button visibility and order

def 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 active

def indicate(indicate_label, page_function):

    clear_indicators()

    indicate_label.config(bg="#158aff")

    page_function()


# Clear all indicators

def 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")


# Initialize the application with the first progress setup

setup_naik_mode(1)


# Start the main loop

root.mainloop()


Kode tersebut akan menyelesaikan bagian yang diminta dengan mengatur elemen GUI tambahan serta fungsionalitas yang diperlukan untuk aplikasi.



Bersambung ke :

MRMBUKA FILE DI PYTHON DAN MENJALANKAN ISINYA DENGAN PERINTAH EXEC (Part-2)




Komentar

Postingan populer dari blog ini

Pemograman R Studio

  Metode Numerik Menggunakan R Pengantar Gambaran Isi Buku Cara Berkontribusi dalam Buku Ini Ucapan Terima Kasih Lisensi 1  Bahasa Pemrograman R 1.1  Sejarah R 1.2  Fitur dan Karakteristik R 1.3  Kelebihan dan Kekurangan R 1.4  RStudio 1.5  Menginstall R dan RStudio 1.6  Working Directory 1.6.1  Mengubah Lokasi Working Directory 1.6.2  Mengubah Lokasi Working Directory Default 1.7  Memasang dan Mengaktifkan Paket R 1.8  Fasilitas Help 1.8.1  Mencari Help dari Suatu Perintah Tertentu 1.8.2  General Help 1.8.3  Fasilitas Help Lainnya 1.9  Referensi 2  Kalkulasi Menggunakan R 2.1  Operator Aritmatik 2.2  Fungsi Aritmetik 2.3  Operator Relasi 2.4  Operator Logika 2.5  Memasukkan Nilai Kedalam Variabel 2.6  Tipe dan Struktur Data 2.7  Vektor 2.7.1  Membuat vektor 2.7.2  Missing Values 2.7.3  Subset Pada Vektor 2.7.4  Operasi Matematis Menggunakan Vektor ...

MIGRASI DATABASE DARI SQLite KE MySQL (Part-1)

  MIGRASI DATABASE DARI SQLite KE MySQL (Part-1) Pemakaian yang mana lebih baik dalam membuat database_musik di mysql atau Exel yang cell Cell pada tabel dilakukan operasi fungsi logika matematika. Untuk keperluan membuat database atau tabel yang memerlukan operasi logika atau matematika, seperti yang Anda sebutkan, MySQL jauh lebih baik dibandingkan Excel. Berikut adalah beberapa alasan mengapa MySQL lebih disarankan: 1. **Kapasitas dan Skalabilitas**: MySQL dapat menangani jumlah data yang jauh lebih besar daripada Excel. Ini penting jika Anda berencana untuk menyimpan banyak data atau melakukan operasi yang kompleks di atas data tersebut. 2. **Kekuatan dan Kinerja**: MySQL dirancang khusus untuk memproses query dan operasi basis data dengan cepat. Ini termasuk operasi matematika, logika, dan agregasi data yang umum dilakukan dalam aplikasi. 3. **Fleksibilitas Struktur**: Dalam MySQL, Anda dapat dengan mudah menentukan struktur tabel yang kompleks dan melakukan kueri yang lebih r...

Cara Menjadi Pengembang Front End – Keterampilan Front End Web Dev

  Menyumbangkan Belajar coding —  kurikulum 3.000 jam gratis 10 JUNI 2022 / #PENGEMBANGAN UJUNG DEPAN Bagaimana Menjadi Pengembang Front End – Keterampilan Front End Web Dev Joel Olawanle Beberapa profesional dengan bayaran tertinggi di dunia adalah pengembang front-end.  Mereka menggunakan pengetahuan dan bakat mereka untuk merancang situs web yang menarik dan ramah pengguna. Pengembang front-end tidak memerlukan gelar atau sertifikat sekolah untuk bekerja.  Sebaliknya, mereka harus memahami dasar-dasar pengembangan front-end, bahasa pemrograman, dan kerangka kerja pengembangan front-end. Dalam panduan ini, Anda akan belajar bagaimana menjadi pengembang front end dengan terlebih dahulu memahami apa yang dimaksud dengan pengembangan front end, keterampilan teknis dan soft skill yang diperlukan, bahasa dan kerangka kerja yang tersedia, dan beberapa langkah untuk memulai. Seorang pengembang front-end di Amerika Serikat dapat memperoleh rata-rata $86,178 per tahun, menu...