0

I want to create label widgets in the RecordsFrame class using a button in the FrameWithButton class. How do I do that? I can't just run the RecordsFrame create_column() func through the button command

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

# example list of records
all_records = [[0, "English", 50, 100, "Quiz", "May 5, 2023", "Passed!"],
               [1, "Math", 50, 100, "Quiz", "May 5, 2023", "Failed."], 
               [2, "History", 50, 100, "Quiz", "May 5, 2023", "Passed!"]]

# frame containing records
class RecordsFrame(ctk.CTkFrame):
    def __init__(self, parent):
        super().__init__(parent)
        self.rowconfigure(0, weight = 1)
        self.columnconfigure(0, weight = 1)
        self.grid(row = 0, column = 0, sticky = 'nsew', padx = 10, pady = 10)

        self.create_column()

    def create_column(self):
        for i in range(len(all_records)):
            rowid_index = i
            rowid_cell = ctk.CTkLabel(
                self,
                text = str(all_records[i][1]),
            )
            rowid_cell.grid(row = i+1, column = 0)
            rowid_index += 1

#frame containing button
class FrameWithButton(ctk.CTkFrame):
    def __init__(self, parent):
        super().__init__(parent)
        self.rowconfigure(0, weight = 1)
        self.columnconfigure(0, weight = 1)

        self.grid(row = 1, column = 0, sticky = 'nsew')

        button = ctk.CTkButton(
            self,
            command = # I want this command to create the widgets in the RecordsFrame class,
            text = "Make widgets"
        )
        button.grid(row = 0, column = 0, sticky = "nsew", padx = 10, pady = 10)

class MyApp(ctk.CTk):
    def __init__(self):
        super().__init__()
        self.geometry("600x600")
        self.title("Test Window")
        self.rowconfigure(0, weight = 1)
        self.rowconfigure(1, weight = 1)
        self.columnconfigure(0, weight = 1)

        self.r_frame = RecordsFrame(self)
        self.button_frame = FrameWithButton(self)

My_app = MyApp()
My_app.mainloop() 

I don't know enough about how tkinter works to run the function from a different frame class. Can anyone help? Thanks!

Canoe
  • 9
  • 2

0 Answers0