ttkbootstrap
ttkbootstrap copied to clipboard
Tableview updates the data in the table, but get_rows() remains with old data.
Desktop (please complete the following information):
ttkbootstrap Version [1.9.0] --> pip3 install ttkbootstrap-master.zip OS: [Linux Mint cinnamon x64 X11]
Describe the bug
When editing a tableview, the data is updated on the screen. But get_rows() returns the data before editing.
To Reproduce
Am I doing something wrong, or get_rows() doesn't update after editing the tableview?
In the code below, follow the steps below:
-
I click the 'add row' button, and it adds a new row in the table --> with get_rows() I pass the table contents to the variable 'matriz'
-
In the table, I click on the cell with the pencil icon
-
in the entrys above the table, I change the first name / last name
-
I click the 'Confirm Edit' button --> with get_rows() I pass the table contents to the variable 'matriz'
There the problem occurs, on the screen the table is displayed correctly with the name changed. But the variable 'matriz' was not changed, it remains the same before editing.
from tkinter import *
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.tableview import Tableview
from tkinter import messagebox as msg
def add_row():
dt.insert_row(END, ['Jimmy', 'Doe' , '📄🖉', '❌'])
dt.load_table_data()
rows_obj = dt.get_rows()
matriz = [row.values for row in rows_obj]
print('var matriz --> Before edit - table itens:', matriz)
return
def update_row():
btn_edit.configure(state=DISABLED)
btn_add.configure(state=NORMAL)
dt.view.configure(selectmode=EXTENDED)
dt.configure(bootstyle='primary-table')
rows = [[vfname.get(), vlname.get(), '📄🖉', '❌']]
if rows != []:
selected = dt.view.focus()
for item in rows:
dt.view.item(selected, values=item)
dt.load_table_data()
rows_obj = dt.get_rows()
matriz = [row.values for row in rows_obj]
print('var matriz --> After editing - table itens:', matriz)
return
def on_select_dt_item(event=None):
table_mode = str(dt.view.cget('selectmode'))
if table_mode == 'extended':
curItem = dt.view.item(dt.view.focus())
col = dt.view.identify_column(event.x)
region = dt.view.identify_region(event.x, event.y)
if region == 'cell':
if col == '#3': #'cell' edit
vfname.set(curItem['values'][0])
vlname.set(curItem['values'][1])
btn_edit.configure(state=NORMAL)
btn_add.configure(state=DISABLED)
dt.view.configure(selectmode='none')
dt.configure(bootstyle='secondary-table')
if col == '#4': #'cell' delete
iids = dt.view.selection()
if len(iids) > 0:
if msg.askyesno('Warning', f'Confirm Deletion?', parent=app):
prev_item = dt.view.prev(iids[0])
dt.delete_rows(iids=iids)
dt.view.focus(prev_item)
dt.view.selection_set(prev_item)
return
app = ttk.Window()
vfname = StringVar()
vlname = StringVar()
frame1 = ttk.Frame(app)
frame1.pack()
ent_fname = ttk.Entry(frame1, textvariable=vfname)
ent_fname.pack(side=LEFT)
ent_lname = ttk.Entry(frame1, textvariable=vlname)
ent_lname.pack(side=LEFT)
btn_edit = ttk.Button(frame1, text='Confirm Edit', command=update_row)
btn_edit.pack(side=LEFT)
btn_edit.configure(state=DISABLED)
columns = [
{'text': 'First Name', 'stretch': True},
{'text': 'Last Name', 'stretch': True},
{'text': '', 'stretch': False, 'anchor': CENTER},
{'text': '', 'stretch': False, 'anchor': CENTER}
]
data = []
dt = Tableview(app, coldata=columns, rowdata=data)
dt.pack()
dt.view.bind('<ButtonRelease-1>', on_select_dt_item)
btn_add = ttk.Button(app, text='Add Row', command=add_row)
btn_add.pack()
app.mainloop()
Expected behavior
The value of the variable 'matriz' before editing is this:
[['Jimmy', 'Doe', '📄🖉', '❌']]
After editing it should be this:
[['new name', 'test', '📄🖉', '❌']]
the expected value for the variable 'matriz' after editing would be the same as this list:
matriz = [dt.view.item(item.iid)['values'] for item in dt._tablerows]
Screenshots
Additional context
No response