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()これにより、メソッドの挿入位置キーボードで入力されたテキストの挿入位置の両方が移動します。テキストウィジェットをクリックした通常の効果がカーソルの再配置を上書きしないように、少し遅延が必要であることがわかりました:)

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 に答える