2013-02-27 53 views
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() 

謝謝

+0

實際上它應該移動光標。你能顯示你的代碼嗎? – Junuxx 2013-02-27 17:31:20

回答

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() 
+0

'code'(從進口的Tkinter * DEF curseur(BIDON): mytext.mark_set(INSERT,END) 根= Tk的() mytext的=文本(根) mytext.pack() mytext.insert (INSERT,「Clic in other window,then clic back here(line one)\ n」) mytext.insert(INSERT,「鍵入鍵盤上的內容\ n」) mytext.insert(INSERT,「鍵入的文本必須()「 mytext.bind(」「,curseur) root.mainloop() ) – 2013-02-27 17:54:11

+0

對不起,請看下面的答案 – 2013-02-27 17:57:36

+0

@ A.Oumnad:那什麼都行不通?當我嘗試你的代碼時,文本*不會*轉到小部件的末尾。 – Junuxx 2013-02-27 18:00:48

相關問題