Skip to content

Keys can be anything......including a tuple (row,col) #2

@MikeTheWatchGuy

Description

@MikeTheWatchGuy

For layouts like this, a grid, I like to use TUPLES as the key for the buttons. This is what I did in the Chess game from what I recall. I've done it a number of times in demo programs too. The Table Simulation demo program uses one of these kinds of keys.

There is no need to turn your row and column variables into strings so that they can be made into a "key".

Instead of this:
key=str(row)+','+str(col)
You can do this:
key=row,col

There is no requirement that keys be strings. They can be anything you want, including a tuple. When one of these buttons is clicked, the event that's returned is row, col.

Then, later, if you want to lookup that Button Element you can use FindElement (or the shortened version Element)....

button = window.Element((row,col))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions