0
我試圖使用Text
小部件實現命令控制檯。在下面的代碼中,當我點擊「返回」鍵時,插入提示後光標移動到下一行。我無法在提示符下使光標位置。我試圖捕獲x,y座標,但它也沒有幫助。Tkinter文本窗口小部件光標在特定行上
from Tkinter import *
def getCommand(*args):
global text
x_pos = text.xview()[0]
y_pos = text.yview()[0]
text.insert(END, "\n")
text.insert(END, "command>")
root = Tk()
text = Text(root)
text.pack()
text.insert(END,"command>")
text.focus()
text.bind("<Return>",getCommand)
root.mainloop()
謝謝,它的工作。 – sarbjit