diff options
author | navanchauhan <navanchauhan@gmail.com> | 2023-05-18 13:13:32 -0600 |
---|---|---|
committer | navanchauhan <navanchauhan@gmail.com> | 2023-05-18 13:13:32 -0600 |
commit | a0aa9a59190b46080cba828cd4903cc582541347 (patch) | |
tree | e34fe04fef7f89f6fcc83080835f7c9b28084f7d | |
parent | 767f4321b5c0077432c81b6c99ff52d4632cd127 (diff) |
add num companies selected label
-rw-r--r-- | main.py | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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('<<ListboxSelect>>', 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() |