Linked Questions

Popular Questions

import tkinter as tk
from tkinter import ttk
import customtkinter as ctk

class FieldsFrame(ctk.CTkFrame):
    def __init__(self, parent, **kwargs):
        super().__init__(parent, **kwargs)

        # Grid Configuration
        self.rowconfigure(0, weight = 1)
        self.columnconfigure(0, weight = 1)
        self.columnconfigure(1, weight = 1)
        self.columnconfigure(2, weight = 1)
        self.columnconfigure(3, weight = 1)
        self.columnconfigure(4, weight = 1)
        self.columnconfigure(5, weight = 1)
        self.columnconfigure(6, weight = 1)

        self.grid(row = 0, column = 0, columnspan = 3, sticky = "WES", padx = 10, pady = 0)
        
        # Create Widgets
        self._create_widgets()

        
    def _create_widgets(self):
        options = {'padx': 5, 'pady': 5, 'font': ("Century Gothic", 20)}
        self.LRowid = ctk.CTkLabel(
            self,
            text = 'rowid',
            **options
        )
        self.LRowid.grid(row = 0, column = 0, sticky = "N")

        self.LSubject = ctk.CTkLabel(
            self,
            text = 'Subject',
            **options
        )
        self.LSubject.grid(row = 0, column = 1, sticky = "N")
        
        self.LScore = ctk.CTkLabel(
            self,
            text = 'Score',
            **options
        )
        self.LScore.grid(row = 0, column = 2, sticky = "N")
        
        self.LTotal = ctk.CTkLabel(
            self,
            text = 'Total',
            **options
        )
        self.LTotal.grid(row = 0, column = 3, sticky = "N")
        
        self.LWorktype = ctk.CTkLabel(
            self,
            text = 'Worktype',
            **options
        )
        self.LWorktype.grid(row = 0, column = 4, sticky = "N")
        
        self.LDate = ctk.CTkLabel(
            self,
            text = 'Date',
            **options
        )
        self.LDate.grid(row = 0, column = 5, sticky = "N")
        
        self.LEval = ctk.CTkLabel(
            self,
            text = 'Evaluation',
            **options
        )
        self.LEval.grid(row = 0, column = 6, sticky = "N")

class DatabaseFrame(ctk.CTkScrollableFrame):
    def __init__(self, parent, **kwargs):
        super().__init__(parent, **kwargs)
        
        # Grid Config
        self.rowconfigure(0, weight = 1)
        self.columnconfigure(0, weight = 1)
        self.columnconfigure(1, weight = 1)
        self.columnconfigure(2, weight = 1)
        self.columnconfigure(3, weight = 1)
        self.columnconfigure(4, weight = 1)
        self.columnconfigure(5, weight = 1)
        self.columnconfigure(6, weight = 1)

        self.grid(row = 1, column = 0, columnspan = 3, sticky = "NWES", padx = 10, pady = 10)

        # Create Widgets from data
          
class InputFrame(ctk.CTkFrame):
    def __init__(self, parent, **kwargs):
        super().__init__(parent, **kwargs)

        # Grid Layout Configuration
        self.rowconfigure(0, weight = 1)
        self.rowconfigure(1, weight = 1)
        self.rowconfigure(2, weight = 1)
        self.columnconfigure(0, weight = 1)
        self.columnconfigure(1, weight = 2)
        self.columnconfigure(2, weight = 1)
        self.columnconfigure(3, weight = 2)


        self.configure(
            # Insert color here
        )
        self._create_widgets()
        self.grid(row = 2, column = 1, columnspan = 1, sticky = "nsew", ipadx = 20, ipady = 20, padx = 30, pady = 10)
        
    def _create_widgets(self):
        _label_options = {'padx': 10, 'pady': 5, 'font': ("Century Gothic", 20)}
        _entry_options = {'fg_color': "white", 'corner_radius': 10}

        # Create subject label and entries
        self.LSubject = ctk.CTkLabel(
            self,
            text = "Enter subject:",
            **_label_options
        ).grid(row = 0, column = 0, sticky = "w")
        
        self.LSubject = ctk.CTkEntry(
            self,
            placeholder_text = "Enter subject:",
            **_entry_options
        ).grid(row = 0, column = 1, sticky = "ew")

        # Create score label and entries
        self.LScore = ctk.CTkLabel(
            self,
            text = "Enter score:",
            **_label_options
        ).grid(row = 0, column = 2, sticky = "w")

        self.LScore = ctk.CTkEntry(
            self,
            placeholder_text = "Enter score:",
            **_entry_options
        ).grid(row = 0, column = 3, sticky = "ew")

        # Create total label and entries
        self.LTotal = ctk.CTkLabel(
            self,
            text = "Score over total:",
            **_label_options
        ).grid(row = 1, column = 2, sticky = "w")

        self.LTotal = ctk.CTkEntry(
            self,
            placeholder_text = "Score over total:",
            **_entry_options
        ).grid(row = 1, column = 3, sticky = "ew")

        # Create Worktype label and entries
        self.LWorktype= ctk.CTkLabel(
            self,
            text = "Enter worktype:",
            **_label_options
        ).grid(row = 1, column = 0, sticky = "w")

        self.LWorktype = ctk.CTkEntry(
            self,
            placeholder_text = "Enter worktype:",
            **_entry_options
        ).grid(row = 1, column = 1, sticky = "ew")

        # Create Date label and entries
        self.LDate = ctk.CTkLabel(
            self,
            text = "Enter date:",
            **_label_options
        ).grid(row = 2, column = 0, sticky = "w")
        
        self.LDate = ctk.CTkEntry(
            self,
            placeholder_text = "Enter date:",
            **_entry_options
        ).grid(row = 2, column = 1, sticky = "ew")

    


class MainApp(ctk.CTk):
    def __init__(self):
        super().__init__()
        self.width = self.winfo_screenwidth()
        self.height = self.winfo_screenheight()
        self.title("Test Window")
        self.geometry(f"{self.width}x{self.height}")
        self.state("zoomed")
        # self.resizable(0, 0)
        
        self.rowconfigure(0, weight = 1)
        self.rowconfigure(1, weight = 4)
        self.rowconfigure(2, weight = 1)
        self.columnconfigure(0, weight = 1)
        self.columnconfigure(1, weight = 2)
        self.columnconfigure(2, weight = 1)

        self.db_frame = DatabaseFrame(self)
        self.input_frame = InputFrame(self)
        self.fields_frame = FieldsFrame(self)

Main_app = MainApp()
Main_app.mainloop()

I want to insert records into columns from a database. I'm fairly new to GUI so I'm not quite sure how to even start doing it.

I tried looping through the list and only accessing the second index of an SQLite record list. but I also thought about how to go about sorting the records by subject or date.

Related Questions