[Tkinter] Scroll at cursor position - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Scroll at cursor position (/thread-7943.html) |
Scroll at cursor position - lollo - Jan-30-2018 Hi guys, I'm new on this forum. I registered for despair :( I have a (maybe little) problem with the Text widget. When I paste some text from clipboard and the last line leave out of form view, the scroll bar (or text widget) doesn't move on cursor position. I found this function: IMPORTFILES_list.bind("<KeyPress>", gotocursor) and the function: def gotocursor(event): IMPORTFILES_list.insert(END, "") IMPORTFILES_list.see(END) but every time that I press any key, the function want to go to the cursor. I would like that this function will be recall only if I paste along text with ctrl + V. Someone can hel me? Many thanks RE: Scroll at cursor position - Gribouillis - Jan-30-2018 You could perhaps bind the Control-v event from tkinter import * def foo(event): print('foo() was called with', event) root = Tk() T = Text(root, height=10, width=30) T.pack() T.bind('<Control-v>', foo) T.insert(END, "Just a text Widget\nwith 2 lines\n") mainloop() RE: Scroll at cursor position - lollo - Jan-31-2018 Hi Gribouillis, wow, works!!! Many thanks for your replay. I don't knew that you can put "Control-v"... It works, but it should do it when I release the keys... Maybe with a delay? Hi Gribouillis, wow, works!!! Many thanks for your reply. I don't knew that you can put "Control-v"... It works, but it should do it when I release the keys... Maybe with a delay? RE: Scroll at cursor position - Gribouillis - Jan-31-2018 (Jan-31-2018, 06:50 AM)lollo Wrote: Maybe with a delay?Or maybe by setting a variable and catching the release of the v key. See if this works from tkinter import * CVPRESS = False def foo(event): global CVPRESS CVPRESS = True def bar(event): global CVPRESS if not CVPRESS: return CVPRESS = False print('bar() was called') root = Tk() T = Text(root, height=10, width=30) T.pack() T.bind('<Control-v>', foo) T.bind('<KeyRelease-v>', bar) T.insert(END, "Just a text Widget\nwith 2 lines\n") mainloop() RE: Scroll at cursor position - lollo - Jan-31-2018 Great, Gribouillis!!! It works fine to me. Many many thanks |