0

i'm doing a tkinter application, and i have this problem:

I have a Frame with this code:

class SelectFrame(customtkinter.CTkFrame):
    def __init__(self, master, back):
        super(SelectFrame, self).__init__(master)
        self.configure(width=120, height=60, border_width=2,)
        self.master = master
        self.menu = ""
        self.input = ""
        self.back = back
        self.create_widgets()


    def create_widgets(self):

        def segmented_button_callback(value):
            if value == "Menu":
                import menu_frame
                self.menu = menu_frame.MenuFrame(self.master, self.back).place(x=25, y=125)

            if value == "Inputs":
                import input_frame
                self.input = input_frame.InputFrame(self.master, self.back).place(x=25, y=125)

        segemented_button = customtkinter.CTkSegmentedButton(master=self,
                                                             values=["Menu", "Inputs"],
                                                             command=segmented_button_callback,
                                                             width=100,
                                                             height=40,
                                                             selected_hover_color="blue",
                                                             font=("Helvetica", 14))
        segemented_button.place(x=10, y=10)

The idea its that, when you click on Menu it creates a Menu Frame, and the same with the Input Frame. The problem is that when i click on Input Frame, the background becomes white.

The menu frame

The input frame hahaha :(

Here's the input frame code:

class InputFrame(customtkinter.CTkFrame):

    # CONSTRUCTOR FOR THE CLASS
    def __init__(self, master, back):
        super(InputFrame, self).__init__(master)
        self.master = master
        self.configure(width=850, height=350)
        self.table = ttk.Treeview(self, columns=("c1", "c2"), show='headings')
        self.lbl_error = customtkinter.CTkLabel(master=self.master, text="", text_color="red")
        self.style()
        self.back = back
        self.createWidgets()

    # METHOD TO CHANGE THE STYLE OF THE TREEVIEW
    def style(self):
        # STYLE FOR TABLE
        style = ttk.Style()

        style.configure("Treeview",
                        background="#2a2d2e",
                        foreground="white",
                        fieldbackground="#343638",
                        bordercolor="#343638",
                        rowheight=35,
                        borderwidth=0,
                        font=(None, 16))
        style.map('Treeview', background=[('selected', '#22559b')])

        style.configure("Treeview.Heading",
                        background="#565b5e",
                        foreground="white",
                        font=(None, 16))
        style.map("Treeview.Heading",
                  background=[('active', '#3484F0')])

    # METHOD TO CREATE THE WIDGETS
    def createWidgets(self):
        """logging.basicConfig(format='%(asctime)s.%(msecs)03d %(levelname)s {%(module)s} [%(funcName)s] %(message)s',
                            datefmt='%Y-%m-%d,%H:%M:%S', level=logging.DEBUG)
        logging.info("start")"""

        # TITLE FOR MOD 2
        lbl_mod2 = customtkinter.CTkLabel(master=self, text="INPUTS INFO", font=("Helvetica", 16))
        lbl_mod2.place(x=380, y=10)

        # CREATING TABLE TO VIEW INPUT'S DATA
        self.table['columns'] = ('input', 'pulses')

        # DEFINITION OF COLUMNS
        self.table.column("input", width=300, anchor="center")
        self.table.column("pulses", width=500, anchor="center")

        # HEADERS
        self.table.heading("input", text="INPUT")
        self.table.heading("pulses", text="Nº PULSES")
        self.updateData()
        self.table.place(x=225, y=60)

        # LABEL FOR ERROR
        self.lbl_error.place(x=180, y=430)

    # METHOD TO UPDATE ALL THE DATA EVERY SECOND, AND WHEN PRESS REFRESH BUTTON
    def updateData(self):
        self.table.delete(*self.table.get_children())
        pulses = []
        try:
            pulses = self.back.get_pulses()
            self.lbl_error.configure(text="")
        except:
            self.lbl_error.configure(text="ERROR: Cannot get info from device")
            self.after(1000, lambda: self.updateData())

        for i in range(8):
            self.table.insert(parent='', index='end',
                              values=('INPUT ' + str(i + 1), pulses[i]))  #

        self.after(1000, lambda: self.updateData())

I really don't have any idea of why is this happening, because i made so many changes on the app, and it wasn't working wrong after this new structure hahahaha

Thank u all :)

0 Answers0