ragardner / tksheet

Python tkinter table widget for displaying tabular data
https://pypi.org/project/tksheet/
MIT License
400 stars 48 forks source link

Problem with right click popup menu inside the cell #245

Closed m64s closed 2 months ago

m64s commented 2 months ago

when i right click with open cell the menu (copy, cut, ...) are repeated (when I out of the cell then become inside again its repeated)

its become like copy, cut, paste, select all, copy, cut, paste, select all, copy, cut, paste, select all,

this happen by default i didnt change on the popup menu

m64s commented 2 months ago

ok i fix it, the problem in text_editor.py

step to fix it:

1- go to text_editor.py 2- edit on def reset() (the first one) 3- change self.rc_popup_menu.delete(0, None) to self.rc_popup_menu.delete(0, 'end')

the full code of def reset() :

def reset(
    self,
    menu_kwargs: dict,
    sheet_ops: dict,
    align: str,
    font: tuple,
    bg: str,
    fg: str,
    state: str,
    text: str = "",
) -> None:
    # Configure text widget properties
    self.config(
        font=font,
        background=bg,
        foreground=fg,
        insertbackground=fg,
        state=state,
    )
    self.align = align

    # Clear existing commands from the popup menu
    self.rc_popup_menu.delete(0, 'end')

    # Add new commands to the popup menu
    self.rc_popup_menu.add_command(
        label=sheet_ops.select_all_label,
        accelerator=sheet_ops.select_all_accelerator,
        command=self.select_all,
        **menu_kwargs,
    )
    self.rc_popup_menu.add_command(
        label=sheet_ops.cut_label,
        accelerator=sheet_ops.cut_accelerator,
        command=self.cut,
        **menu_kwargs,
    )
    self.rc_popup_menu.add_command(
        label=sheet_ops.copy_label,
        accelerator=sheet_ops.copy_accelerator,
        command=self.copy,
        **menu_kwargs,
    )
    self.rc_popup_menu.add_command(
        label=sheet_ops.paste_label,
        accelerator=sheet_ops.paste_accelerator,
        command=self.paste,
        **menu_kwargs,
    )
    self.rc_popup_menu.add_command(
        label=sheet_ops.undo_label,
        accelerator=sheet_ops.undo_accelerator,
        command=self.undo,
        **menu_kwargs,
    )

    # Configure text widget alignment
    align = convert_align(align)
    if align == "w":
        self.align = "left"
    elif align == "e":
        self.align = "right"

    # Update text widget content and formatting
    self.delete(1.0, "end")
    self.insert(1.0, text)
    self.yview_moveto(1)
    self.tag_configure("align", justify=self.align)
    self.tag_add("align", 1.0, "end")
ragardner commented 2 months ago

Thanks for your report and your fix which I will add in the next update

m64s commented 2 months ago

thank you, I hope you add Cell merging also and a way to remove the grid or border for individual cell or make the color of it to white like the sheet background to hide it like Excel