0

Given the following Tkinter GUI with PandasTable, I would like to return the entirety of a row based on the user's selection. Ideally, I'd like to throw it into a new dataframe that I can manipulate and work with. I did find some information regarding getSelectedRow() and get_row_clicked(), but haven't been able to piece enough together to do what I am hoping to do. Further down is a function that I found and tried to make meet my needs, but I am kind of at a loss. Any help would be appreciated.

from pandastable import Table, TableModel
import tkinter as tk
import pandas as pd

df = pd.DataFrame(np.random.randn(6,4),columns=list("ABCD"))

app = tk.Toplevel()

app.title('Table app')
f = tk.Frame(app)
f.pack(fill=BOTH,expand=1)

table = pt = Table(f, dataframe=df, showtoolbar=True, showstatusbar=True)

pt.show()

pt.rowheader.bind('<Button-1>',handle_left_click)

app.mainloop()

Here is what I have tried, but it only returns the index. Ideally I would build a new dataframe based on the user's selection and I would do this on a tk.Button() event. Again, any help would be greatly appreciated.

def handle_left_click(event):
    """Handle left click"""
    rowclicked_single = table.get_row_clicked(event)
    print(rowclicked_single)
    table.setSelectedRow(rowclicked_single)
    table.redraw()
JRiggles
  • 4,847
  • 1
  • 12
  • 27

0 Answers0