appJar icon indicating copy to clipboard operation
appJar copied to clipboard

Remove by position

Open mpmc opened this issue 7 years ago • 4 comments

Would it be possible to have a method to remove any widget by its position instead of title?

mpmc avatar Feb 11 '18 22:02 mpmc

Does sound reasonable - appJar uses grid layout, so if it’s supported, we can do it...

jarvisteach avatar Feb 12 '18 10:02 jarvisteach

According to this article: https://stackoverflow.com/questions/23189610/remove-widgets-from-grid-in-tkinter you can iterate over items in a grid:

for label in a.grid_slaves():
    if int(label.grid_info()["row"]) > 6:
        label.grid_forget()

jarvisteach avatar Feb 12 '18 15:02 jarvisteach

As demonstrated in the code committed above, it's easy enough to iterate over all widgets in the grid, and get their position.

So, removing by position would just be a case of performing the above, and removing the relevant widget.

However, it would also need to be removed from the relevant dictionary in the widget store, and potentially other places...

jarvisteach avatar Feb 12 '18 16:02 jarvisteach

There are many remove methods removeXXX(name).

These could all be replaced by a single remove that could accept positions, or name (perhaps change this to title to match the others?), and an optional kind parameter. If no kind (or position) is set try and remove ALL widgets of name.


remove((0, 0), (0, 1))
remove('mylabels', 'my entries')
remove('mylabel', kind='label')

Maybe renaming removeAllWidgets to removeAll, or even just remove. with no arguments?

mpmc avatar Feb 13 '18 06:02 mpmc