Closed serghPeppa closed 4 months ago
Also i have this peace of code that work for my window, except sheet, maybe this can help you
def _onKeyRelease(event):
ctrl = (event.state & 0x4) != 0
if event.keycode==86 and ctrl and event.keysym.lower() != "v":
event.widget.event_generate("<<Paste>>")
if event.keycode==67 and ctrl and event.keysym.lower() != "c":
event.widget.event_generate("<<Copy>>")
main.bind_all("<Key>", _onKeyRelease, "+")
Hello,
Thanks for your question and the interesting code snippet,
I am not sure how best to get those custom events working in tksheet at the moment, it will take some experimentation if I do decide to implement it
In the meantime, would this solution work for you? You can replace the characters with whichever you need
sheet.set_options(paste_bindings=["<Control-м>", "<Control-М>"])
More info here: https://github.com/ragardner/tksheet/wiki/Version-7#changing-key-bindings
It's not working if i type cyrillic symbol inside it. It gives this error: _tkinter.TclError: bad event type or keysym "с" Maybe you can make an overload of this option, where I will be able to use keycode instead of keysym? This will immediately solve my problem.
Hello,
I am working on this and I think I have a solution that will make the code you provided work for tksheet, meaning that widget.event_generate("<<Copy>>")
will tell tksheet to run the copy function.
I am not currently working on ways of binding the keycodes though sorry, this seems a bit more complex and would warrant more investigation.
There will also separately be an optional way of specifically binding the "<<Copy>>"
event to tksheet.
Your help has been invaluable in figuring this out thank you, I will let you know when there is a new release
I'm very glad to hear this! I hope you can do this. Thank you for your work!
Hello,
I have released a new version which should allow you to call event_generate()
on a Sheet, with "<<Copy>>"
and so also for paste, delete, cut, undo, redo and selectall
Some new documentation here: https://github.com/ragardner/tksheet/wiki/Version-7#tkinter-and-tksheet-events
csv.Sniffer().sniff()
without setting sample size, now only samples 5000 characters maxwidget
key to emitted event dict
s which can be either the header, index or table canvas. If you're using pickle
on tksheet event dict
s then you may need to delete the widget
key beforehandHighlight
, add_highlight
, new_tk_event
and get_csv_str_dialect
to tksheet namespaceNone
now return self
(Sheet
)dict
keys ["moved"]["rows"]["data"]
/["moved"]["columns"]["data"]
but instead returns only the rows/columns which were originally moved.Shift-Return
to text editor newline bindingsclose_text_editor()
function parametersclose_text_editor()
now closes all text editors that are opendropdown()
:
edit_data
to disable editing of data when creating the dropdownsset_values
so a dict
of cell/column/row coordinates and values can be provided instead of using set_value
for every cell in the span"<<Copy>>"
"<<Cut>>"
"<<Paste>>"
"<<Delete>>"
"<<Undo>>"
"<<Redo>>"
"<<SelectAll>>"
highlight_cells()
slight performance boost when calling it thousands of timesdropdown()
/checkbox()
for help when writing codeYou are a genius! You solve it so quick and elegant! Thank you!
But there was a little issue, if you want your sheet to be readonly
you need to set filter on Canvas
in your <<Paste>>
event:
def _onKeyRelease(event):
ctrl = (event.state & 0x4) != 0
if event.keycode==86 and ctrl and event.keysym.lower() != "v":
if event.widget.winfo_class() not in ("Canvas"):
event.widget.event_generate("<<Paste>>")
if event.keycode==67 and ctrl and event.keysym.lower() != "c":
event.widget.event_generate("<<Copy>>")
main.bind_all("<Key>", _onKeyRelease, "+")
But for me it's 100% resolved. And again, thank you so much!
In Cyrillic layout copy and paste works on same keys but 'v' is 'м'(em), and 'c' is 'с'(es). And when i change layout to Russian or Ukrainian copy and paste stops working in sheet.