I have Accountid column in a Dataframe. Now I am using Tkinter to draw some gui. For each Accountid I want to create a separate button.My code is able to do that. But after this, for each button I want to create a subwindow, which would contain some columns for each Accountid. Now the problem is that my code creates sub-window for each button, but it fetches the columns for only the last Accountid.
I would really appreciate if someone can help me.
import tkinter as tk
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
for id in df['AccountId']:##for each id create a button
new_win_button = tk.Button(self, text=id,
command= self.new_window)
new_win_button.pack(side="top", padx=20, pady=20)
def new_window(self):
top = tk.Toplevel(self)# create sub window
print (id)
#print (id is 'id')
label = tk.Label(top, text=s3.loc[s3.AccountId == id][['AccountId','confidence','lift']])
label.pack(side="top", fill="both", expand=True, padx=20, pady=20)
if __name__ == "__main__":
root = tk.Tk()
Example(root).pack(fill="both", expand=True)
root.mainloop()