dmnfarrell / pandastable

Table analysis in Tkinter using pandas DataFrames.
Other
617 stars 127 forks source link

Pandas function requirements #253

Open 2805951124 opened 3 months ago

2805951124 commented 3 months ago

When entering data, you can only save the edited data by entering, and you cannot save the data and display it in the table by removing the focus.

def on_leave(event, table, row, col, previous_value, new_value, current_input): table.model.df.iat[row, col] = new_value
print("Previous cell value:", previous_value) print("New cell value:", new_value) print("Current input:", current_input)

def main_win(): userData = {'Key Type': ['data'], 'Key Data': [''] }

root = tk.Tk()
root.minsize(560, 650)
root.title("Generate Hex")

top_frame = tk.Frame(root)
top_frame.pack(fill="both", expand=True)

table = Table(top_frame, dataframe=pd.DataFrame(userData), showstatusbar=False)
table.show()

table.resizeColumn(1, width=380)

def leave_event(event, table=table):
    row, col = table.getSelectedRow(), table.getSelectedColumn()
    new_value = table.model.df.iat[row, col]
    current_input = table.model.df.iat[row, col]  
    previous_value = table.model.df.iat[row, col]  
    on_leave(event, table, row, col, previous_value, new_value, current_input)

table.bind('<FocusOut>', leave_event)

root.mainloop()

if name == "main": main_win()

dmnfarrell commented 2 months ago

changing this would require adding an 'edit' mode as the current behaviour is what people are used to.