Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when use arrow key move to left , cursor jumping to the first column) #267

Open
Vichai1877 opened this issue Feb 10, 2025 · 8 comments
Open

Comments

@Vichai1877
Copy link

This program from your example ,

I found when use arrow key to move left cursor , cursor alway jumping to first column

from tksheet import Sheet
import tkinter as tk

class demo(tk.Tk):
def init(self):
tk.Tk.init(self)
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self.frame = tk.Frame(self)
self.frame.grid_columnconfigure(0, weight=1)
self.frame.grid_rowconfigure(0, weight=1)
self.sheet = Sheet(self.frame,
data=[[f"Row {r}, Column {c}\nnewline1\nnewline2" for c in range(50)] for r in range(500)])
self.sheet.enable_bindings(
"single_select",
"drag_select",
"edit_cell",
"paste",
"cut",
"copy",
"delete",
"select_all",
"column_select",
"row_select",
"column_width_resize",
"double_click_column_resize",
"arrowkeys",
"row_height_resize",
"double_click_row_resize",
"right_click_popup_menu",
"rc_select",
)
self.sheet.extra_bindings("begin_edit_cell", self.begin_edit_cell)
self.sheet.edit_validation(self.validate_edits)
self.sheet.popup_menu_add_command("Say Hello", self.new_right_click_button)
self.frame.grid(row=0, column=0, sticky="nswe")
self.sheet.grid(row=0, column=0, sticky="nswe")

def new_right_click_button(self, event=None):
    print ("Hello World!")

def begin_edit_cell(self, event=None):
    return event.value

def validate_edits(self, event):
    # remove spaces from any cell edits, including paste
    if isinstance(event.value, str) and event.value:
        return event.value.replace(" ", "")

app = demo()
app.mainloop()

@ragardner
Copy link
Owner

Hello, thanks for your report

I'm sorry to say I cannot re-create this behavior, could you provide more detail please. These are the things I've tried just now with your above code:

  • I have tried using left arrow key inside the cell text editor, it moves one character left as intended.
  • I have tried using left arrow key the move the cell selection one left, it moves one cell left as intended.

Kind regards

@MonkeyCandies
Copy link

I get the same behaviour as described by Vichai1877.
When I use the arrows to navigate; right, up, down all perform as expected.
Left arrow jumps to the furthest left column in one jump.
As I am using this in a non-admin Win10 environment I had to install tksheet into user site-packages directory.
This behaviour occurs in the included demo

from tksheet import Sheet
import tkinter as tk


class demo(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.grid_columnconfigure(0, weight = 1)
        self.grid_rowconfigure(0, weight = 1)
        self.frame = tk.Frame(self)
        self.frame.grid_columnconfigure(0, weight = 1)
        self.frame.grid_rowconfigure(0, weight = 1)
        self.sheet = Sheet(self.frame,
                           data = [[f"Row {r}, Column {c}\nnewline1\nnewline2" for c in range(50)] for r in range(500)])
        self.sheet.enable_bindings()
        self.frame.grid(row = 0, column = 0, sticky = "nswe")
        self.sheet.grid(row = 0, column = 0, sticky = "nswe")


app = demo()
app.mainloop()

@ragardner
Copy link
Owner

Apologies, I discovered it was scrolling to put the selected column on the right hand side of the view when selecting a column that was not totally visible.

The code for the arrow key functions is also very poor, fixes and refactoring incoming soon.

Kind regards and thank you for raising the issue

ragardner added a commit that referenced this issue Feb 25, 2025
- Removed pre-commit due to issues with python version mismatch
@ragardner
Copy link
Owner

Hello,

The issue should be resolved now in 7.4.5 but let me know if you have further issues

@MonkeyCandies
Copy link

Thanks for the swift reply, sadly the issue still persists for me on 7.4.6. Python version is Python 3.12.9
I am on a non-admin win10 account here so will try the same at home where I can control the python version and install location.
Will update if the issue occurs there too.

@MonkeyCandies
Copy link

Confirmed in my own environment with win10 and admin. Python 3.13.2 & tksheet 7.4.6, that the demo script above (and other scripts) still have the 'left arrow jumps to first column' issue.
Thank you :)

ragardner added a commit that referenced this issue Feb 28, 2025
- In case Command-Left was somehow being triggered, only bind it if on MacOS.
- If Home was somehow also being triggered, return "break" after arrowkey_LEFT fn to try to stop it.
@ragardner
Copy link
Owner

Hello, thanks for the testing and report,

I have tried to fix it in 7.4.7, I'm wondering if it's related to the recent binding of Home as pressing the Home key for me has the same behavior.

I've added a "break" to the arrow key left function to try to prevent additional functions from running afterwards in case Home was being triggered and I've unbound Command Left for non-MacOS devices.

@Vichai1877
Copy link
Author

Thanks for the hard work you did so quickly. In the latest version 7.4.7 the arrow keys are working properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants