From a0aa9a59190b46080cba828cd4903cc582541347 Mon Sep 17 00:00:00 2001 From: navanchauhan Date: Thu, 18 May 2023 13:13:32 -0600 Subject: add num companies selected label --- main.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 5ed51c5..8bd80dd 100644 --- a/main.py +++ b/main.py @@ -44,15 +44,27 @@ class CompanySelector: def show_companies(self): self.select_file_button.pack_forget() - self.company_listbox = tk.Listbox(self.master, selectmode=tk.MULTIPLE, exportselection=False) - self.company_listbox.pack() + self.company_listbox = tk.Listbox(self.master, selectmode=tk.MULTIPLE, exportselection=False, height=20) + self.company_listbox.pack(expand=True) for company in self.df["Symbol"]: self.company_listbox.insert(tk.END, company) + + # bind the listbox to an onselect event + self.company_listbox.bind('<>', self.onselect) + + self.num_companies_selected_label = tk.Label(self.master, text="0 companies selected") + self.num_companies_selected_label.pack() + self.create_pyramid_button = tk.Button(self.master, text="Create Pyramid", command=self.create_pyramid) self.create_pyramid_button.pack() + def onselect(self, evt): + w = evt.widget + num_selected = len(w.curselection()) + self.num_companies_selected_label.config(text=f"{num_selected} companies selected") + def create_pyramid(self): selected_companies = [self.company_listbox.get(index) for index in self.company_listbox.curselection()] selected_df = self.df[self.df["Symbol"].isin(selected_companies)].sort_values(by="Weighting", ascending=False) @@ -220,4 +232,5 @@ class CompanySelector: if __name__ == "__main__": root = tk.Tk() app = CompanySelector(root) + #root.geometry("500x200") root.mainloop() -- cgit v1.2.3