tksheet icon indicating copy to clipboard operation
tksheet copied to clipboard

[Proposal] Checkbox onvalue/offvalue

Open skedus opened this issue 3 years ago • 2 comments

Hi Ragardner, I try to move from v5.3.2 to v5.4.0 but with recent changes this is not working for checkbox anymore for my application. In fact it is because I wanted to put some checkbox with some values which are not boolean True/False or 0/1 (I found a dirty way of doing it with v5.3.2 but that will be better to have a tksheet way of doing it)

I build a proposal with a definition of onvalue and offvalue (defined in cell_option) instead editing the cell value itself like: self.cell_options[(r, c)]['checkbox'] = {'check_function': check_function, 'state': state, 'checked': checked, 'onvalue': onvalue, 'offvalue': offvalue, 'text': text}

I put my modifications to tksheet here to get your point of view on that: https://github.com/skedus/tksheet/tree/try_checkbox

with an example of used https://github.com/skedus/tksheet/blob/try_checkbox/examples/example_checkbox_01.py

Tell me if it can be a way of doing it ?

skedus avatar Jul 01 '22 08:07 skedus

Hello,

Would you like to display your on / off values in the table or just have them stored in the sheet data?

ragardner avatar Jul 01 '22 10:07 ragardner

Hi, The on / off value indicate what is the data value in a column sheet data representing true for the checkbox or which value represent false for the checkbox. Then when clicking on the checkbox the data is set in the cell sheet data by those values.

Example for checkbox on column 1: self.data_header = ["val1", "val2"] self.data = [ ["this_is_true", "AAA1"], ["", "BBBB1" ], ["this_is_false", "CCCCC1"], ]

    # the creation could be like that
    checked = True if  value == "this_is_true" else False
    self.sheet.create_checkbox(row, col, checked=checked, onvalue="this_is_true", offvalue="this_is_false", redraw=True)

Do I answer to your question ?

skedus avatar Jul 04 '22 07:07 skedus