Python Forum
[Tkinter] Scroll at cursor position
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Scroll at cursor position
#1
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
Reply
#2
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()
Reply
#3
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?
Reply
#4
(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()
Reply
#5
Great, Gribouillis!!!

It works fine to me. Many many thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Take the variable of a cursor class delcencen 2 1,149 Feb-13-2023, 05:19 AM
Last Post: deanhystad
  [PyQt] QTableView: scroll to top cell of the screen random_nick 2 2,766 Oct-08-2022, 12:29 AM
Last Post: random_nick
  [PyQt] How do I get a QScrollArea to scroll? LavaCreeperKing 9 7,599 Oct-29-2021, 08:33 AM
Last Post: Axel_Erfurt
  Treeview scroll selected node to top rfresh737 1 2,668 Apr-14-2021, 03:27 AM
Last Post: deanhystad
  [Tkinter] canvas widget scroll issue chrisdb 2 3,778 Apr-07-2021, 05:48 AM
Last Post: chrisdb
  [Tkinter] Help with scroll bars kraco 1 2,205 Sep-27-2020, 11:20 PM
Last Post: Larz60+
  [Tkinter] How to place scroll bar correctly scratchmyhead 1 3,896 May-18-2020, 04:17 PM
Last Post: scratchmyhead
  [Tkinter] Finding out what's under the cursor sabresong 3 2,629 Mar-28-2020, 02:52 PM
Last Post: sabresong
  Scroll frame with MouseWheel Nemesis 1 3,556 Mar-25-2020, 09:29 PM
Last Post: Nemesis
  [Kivy] Why I have to click twice to scroll? Hummingbird 0 2,326 Jan-06-2020, 09:08 PM
Last Post: Hummingbird

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020