Giter VIP home page Giter VIP logo

Comments (10)

tepiloxtl avatar tepiloxtl commented on May 31, 2024 1

Huh. For a single moment when making this bug report yesterday I haven't noticed this is select_rows and not row_colors which I have been dealing with a lot lately, that could have helped figuring out the issue :)

Adding select_mode=sg.TABLE_SELECT_MODE_NONE, fixes the issue, thanks!

from pysimplegui.

tepiloxtl avatar tepiloxtl commented on May 31, 2024 1

I'm very grateful for the immense work you do in supporting users both here and on Stack Overflow, I definitely picked a lot of tips over the years from yours and Jasons responses :)

from pysimplegui.

jason990420 avatar jason990420 commented on May 31, 2024

For 4.55.1.19

                if element.enable_click_events is True:
                    treeview.bind('<Button-1>', element._table_clicked)

For 5.0.4.13

                if element.enable_click_events is True:
                    treeview.bind('<ButtonRelease-1>', element._table_clicked)

So it will select last clicked row, then selected all previous clicked rows for 5.0.4.13

Not sure why it changed ?

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 31, 2024

Not sure why it changed ?

Thank you for identifying what changed!

Here is what I wrote in the release notes about this change:

Changed Table click events to be generated on Button Release instead of Button (down). Was not getting the correct selected rows in the values dictionary when the click event was generated using down. Now the selected rows is correct

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 31, 2024

If you click a row and hold the click down, then you'll see that tkinter removes all of the selected row highlights. When you release the button, then the rows are highlighted again. I believe it's this tkinter behavior that is causing the "flash".

from pysimplegui.

jason990420 avatar jason990420 commented on May 31, 2024

The selection for one row is done defaultly by clicking the mouse, and all old selection removed before it.
Now the option enable_click_events=True generate an event to add one new row to existing selection, and update the total selection to the Table elemenet by method update in the event loop by user code.

What I can do is to recover it to old one, like

window = sg.Window('test gui', layout, resizable=True, finalize=True)
window['-TABLE-'].update(values=table, select_rows=list(selected))

tbl = window['-TABLE-']
tbl.widget.unbind('<ButtonRelease-1>')
tbl.widget.bind('<Button-1>', tbl._table_clicked)

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 31, 2024

This will fix it.... add the select_mode parameter to your Table element.

                      select_mode=sg.TABLE_SELECT_MODE_NONE,

Because you are doing your own highlighting, using a mode of 'none' will keep tkinter from removing the previous selection. It will be smooth again.

# Code taken from my code, modified from Demo_Table_Checkmark.py

import PySimpleGUI as sg

table = [["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"], ["☐", "a", "a"]]


BLANK_BOX = '☐'
CHECKED_BOX = '☑'

table_headings = ["☐", "a", "a"]
selected = {i for i, row in enumerate(table) if row[0] == CHECKED_BOX}

layout = [  [sg.Table(values=table, headings=table_headings,
                    max_col_width=25,
                    auto_size_columns=False,
                    col_widths=[3, 5, 20],
                    display_row_numbers=False,
                    justification='center',
                    num_rows=20,
                    key='-TABLE-',
                    selected_row_colors='red on yellow',
                    expand_x=True,
                    expand_y=True,
                    vertical_scroll_only=True,
                    select_mode=sg.TABLE_SELECT_MODE_NONE,
                    enable_click_events=True)]
        ]

window = sg.Window('test gui', layout, resizable=True, finalize=True)
window['-TABLE-'].update(values=table, select_rows=list(selected))


while True:
    event, values = window.read()
    if event[0] == '-TABLE-' and event[2][0] not in (None, -1):   # if clicked a data row rather than header or outside table
        row = event[2][0]
        if table[row][0] == CHECKED_BOX:     # Going from Checked to Unchecked
            selected.remove(row)
            table[row][0] = BLANK_BOX
        else:                               # Going from Unchecked to Checked
            selected.add(row)
            table[row ][0] = CHECKED_BOX
        window['-TABLE-'].update(values=table, select_rows=list(selected))    # Update the table and the selected rows

python_Ge9JQj9r53

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 31, 2024

In 5.0.4.14 I changed the docstring for the Table element. It is not required in order for the code that added:

select_mode=sg.TABLE_SELECT_MODE_NONE,

In PyCharm I was seeing a warning because the parameter was defined as an enum instead of a string.

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 31, 2024

I haven't noticed this is select_rows and not row_colors

That's an interesting observation that I missed..... row colors could have been used perhaps instead of selected rows. Maybe?

I've updated the Table Checkmark Demo Program with this change too. Thank you for indicating you picked up code from the Demo so that it's fixed and the next person won't have this problem.

And, thank you for the "thanks!" image
It's always nice to see that Jason and I are doing a good job of helping PySimpleGUI users be successful.

from pysimplegui.

PySimpleGUI avatar PySimpleGUI commented on May 31, 2024

I'm very grateful

I can't express how much it means to see these words. Thank you so very much. I'm extremely grateful to have grateful users. Maybe it's not unusual or rare, but it sure feels that way. Jason provides the best support I've ever seen, is quicker and more thorough than I am. We're very fortunate.

from pysimplegui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.