0

I have a program where a user inputs an excel file, the program runs some data analysis and then shows the data tables in a tkinter gui using pandastable library. With the pandastable library, users can delete outliers in the table but I can't figure out how to save the updated table back in my program so I can run the data analysis again without the outlying values.

I have a tkinter button set up for this but am stuck on the command function:

for(tab, table) in zip(tab_control, analyzed_data):
  frame = LabelFrame(tab, text='Analyzed Data')
  frame.grid(row=0, column=0)
  data_table = Table(frame, dataframe=table)
  data_table.show()
# Right now, this button runs the remove_outliers function when the button is formed but does not run again when the button is clicked
   remove_outliers_btn = tk.Button(tab, text='Remove Outliers', fg='white', bg='blue', width=20, command=lambda: remove_outliers(table))
   remove_outliers_btn.grid(row=1, column=0)

Below is the command I've tried to use but it runs when the tkinter window is getting set up and then does not run again when I actually click on the button:

def remove_outliers(table):
  updated_table = table
  print(updated_table)

where the idea is that, I have a list of data tables that are being created and displayed in the tkinter window, so the function takes the table as a parameter and returns the specific table that was updated by the user in the pandastable interface.

Like I mentioned, it runs before the window is set up and then does not run again when the button is clicked, so I don't even know if it works to save data once outliers are removed by the user.

anony1414
  • 37
  • 4
  • `remove_outliers()` is executed whenever the button is clicked, it it not what your comment in the code says. However it will always use the *last table* of the for loop inside `remove_outliers()`. – acw1668 Jul 01 '22 at 15:22
  • it's supposed to be that way but for some reason it is printing everything when the button gets set up, and not when clicked @acw1668 – anony1414 Jul 01 '22 at 15:23
  • I have tested your code (after adding missing parts) and does not have the issue you said. So it is better to provide a [mre]. – acw1668 Jul 01 '22 at 15:26
  • I had forgotten to remove a ```pass``` statement before the actually code, so it does work. However, like you said, it only works for the last table in the list. How would I modify it so it works for all tables? @acw1668 – anony1414 Jul 01 '22 at 16:11
  • 1
    Change `command=lambda: remove_outliers(table)` to `command=lambda table=table: remove_outliers(table)`. – acw1668 Jul 01 '22 at 16:12

0 Answers0