0

似乎语句: MyText.mark_set(INSERT, 'new index') 修改 Text .insert() 方法的插入位置,而不是在键盘上键入的文本的插入位置。

换句话说,有没有办法使用 .insert() 方法插入相当于 CTRL-END 键

from tkinter import *

def curseur(bidon):
    mytext.mark_set(INSERT, END)

root = Tk()
mytext = Text(root)
mytext.pack()
mytext.insert(INSERT, "Clic in other window, then clic back here (line one)\n")
mytext.insert(INSERT, "Type something on the keyboard\n")
mytext.insert(INSERT, "The typed text must go to the end of the widget\n")
mytext.bind("<FocusIn>", curseur)
root.mainloop()

谢谢,

4

1 回答 1

1

这确实会移动Text.insert()方法的插入位置在键盘上键入的文本的插入位置。原来你需要一点延迟,以便在 Text 小部件中单击的正常效果不会覆盖我们对光标的重新定位:)

from tkinter import *

def curseur(bidon):
    root.after(50, lambda: mytext.mark_set(INSERT, END))

root = Tk()
mytext = Text(root)
mytext.pack()
mytext.insert(INSERT, "Clic in other window, then clic back here (line one)\n")
mytext.insert(INSERT, "Type something on the keyboard\n")
mytext.insert(INSERT, "The typed text must go to the end of the widget\n")
mytext.bind("<FocusIn>", curseur)
root.mainloop()
于 2013-02-27T17:35:40.917 回答