Wow, a huge "thank you!"
I guess the order your code is written is far better than the way I wrote mine but I struggled to follow all of it. I did however manage to pull the parts I needed and add them to my code. It now all works the way I wanted. I've also managed to get it adapt depending on which Entry boxes you want in each tab.
I'm now just working out how to enter it to a sql database.
Thank you!
I guess the order your code is written is far better than the way I wrote mine but I struggled to follow all of it. I did however manage to pull the parts I needed and add them to my code. It now all works the way I wanted. I've also managed to get it adapt depending on which Entry boxes you want in each tab.
I'm now just working out how to enter it to a sql database.
Thank you!
from tkinter import * from tkinter.ttk import * import sqlite3 ### Create SQLite database and connect to it ### conn = sqlite3.connect('Bookkeeping_Database.sqlite3') cur = conn.cursor() ### Create tkinter window ### root = Tk() root.title("Bookkeeping") root.geometry("800x600") ### Add a Notebook to window ### home_screen = Notebook(root) home_screen.pack(fill="both", expand=1, pady=15) ### Class to add tabs to Notebook with a method to add entry boxes and a save button ### class Create_tab: def __init__(self, tab): self.tab_name = str(tab) self.tab = tab self.tab = Frame(home_screen) self.tab.pack(fill="both", expand=1) home_screen.add(self.tab, text=self.tab_name) self.detail_name_dictionary = {} self.detail_name_list_keys = [] def create_entry_boxes(self, detail_name): self.detail_name = detail_name self.entry_box = Entry(self.tab) self.entry_box.grid(column=1) self.entry_box.insert(0, detail_name) self.detail_name_dictionary[self.detail_name] = self.entry_box self.detail_name_list_keys.append(detail_name) def save_button(self): self.save_button = Button(self.tab, text="Save") self.save_button.grid(column=1) def on_save_button(self, event): for detail_name in self.detail_name_list_keys: entry_value = self.detail_name_dictionary[detail_name].get() print(f' {detail_name} = {entry_value}') cur.execute("CREATE TABLE IF NOT EXISTS " + self.tab_name + " (" + " TEXT, ".join(self.detail_name_list_keys) +" TEXT)") cur.executemany("INSERT INTO "+ self.tab_name +"(" + ", ".join(self.detail_name_list_keys) + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", str(entry_value,)) conn.commit() ### Create Customers tab ### def create_customer_tab(): customer_tab = Create_tab("Customers") entry_boxes = [ "Customer_ID", "Company", "Name", "Address_1", "Address_2", "Address_3", "Address_4", "Email", "Phone_1", "Phone_2", ] for detail_name in entry_boxes: customer_tab.create_entry_boxes(detail_name) customer_tab.save_button() customer_tab.save_button.bind('<Button-1>', customer_tab.on_save_button) #Main create_customer_tab() root.mainloop() conn.close()