0

I have scripted a class below. I basically take some values from a csv file and populate it on the GUI. The listbox populates well and is also selectable. However, before I can even make a selection, I see the "Empty!" comment on my console. Why is my listbox not populating even though its visible on the GUI?

class Table:

    def __init__(self):
       pass


    def get_selection(self):
        n = self.lbx.curselection()
        if n:
            self.s = self.lbx.get(n)
            print(self.s)
            
        else:
            print('Empty!')


    def clicked_new_order(self):

        df = pd.read_csv('data/teno_menu.csv', encoding='unicode escape')
        cat = df.category.unique()
        from main_screen import M

        self.lbx = tk.Listbox(M.disp_frame, background="#ffffbb", foreground="#07ba80",
                         cursor="hand2", justify='center', relief='flat', selectmode='single',
                         activestyle="dotbox", selectbackground="#00ca00",
                         font="-family {arial} -size 12 -weight bold")
        self.lbx.place(relx=0.28, rely=0.265, relheight=0.7, relwidth=0.4)

        t = []
        for ind, item in enumerate(cat):
            self.lbx.insert(ind, item)
            t.append(item)
        print(t)

        self.lbx.bind('<<ListboxSelect>>', self.get_selection())

When I run the main file that calls this class it works without errors but the lbx.curselection()[0] is always returning empty. What am I missing?

therion
  • 415
  • 4
  • 14

0 Answers0