0
cell_icons = {}
image_references = {}
def on_release(event, label, image_path):
    if label in dragged_icons:
      x, y = event.x_root, event.y_root
      x -= table.winfo_rootx()
      y -= table.winfo_rooty()
        # Identify the row and column under the cursor
        item = table.identify_row(y)
        column_index = table.identify_column(x)
    
        if item and column_index:
            column_name = table['columns'][int(column_index.lstrip('#')) - 1]
            if column_name in ["Trigger Parameter", "Action Target"]:
                current_values = table.item(item, 'values')
    
                # Update the specified column
                img = Image.open(image_path)
                img_tk = ImageTk.PhotoImage(img)
    
                cell_identifier = (item, int(column_index.lstrip('#')) - 1)
    
                if cell_identifier in cell_icons:
                    cell_icons[cell_identifier].append(img_tk)
                else:
                    cell_icons[cell_identifier] = [img_tk]
    
                # Keep a reference to the PhotoImage object outside the function
                image_references[(cell_identifier, label)] = img_tk
    
                updated_values = list(current_values[:cell_identifier[1]]) + [cell_icons[cell_identifier]] + list(
                    current_values[cell_identifier[1] + 1:])
                table.item(item, values=updated_values)
    
                initial_x, initial_y, _, _ = table.bbox(item, column=column_name)
                frame_spacing = 5
    
                labels_in_cell = []  # Keep track of labels in the cell
    
                for i, icon in enumerate(cell_icons[cell_identifier]):
                    canvas = tk.Canvas(table, width=25, height=25, highlightthickness=0)
                    canvas.place(x=initial_x + (i * 25 + i * frame_spacing), y=initial_y)
    
                    label_in_cell = tk.Label(table, image=icon, borderwidth=0)
                    label_in_cell.pack(fill='both', expand=True)
                    labels_in_cell.append(label_in_cell)`your text`

I included options to swap rows and scroll. When I drop an icon into one of the designated columns' cells, its objects are saved, but the label of the picture is dropped onto the cell. I want the picture labeled to move along with the scrolled and swapped functionality whenever I scroll and swap the table rows, but the labels stay in place and just the stored objects change.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.