from Tkinter import *
root = Tk()
t = Text()
for i in range(1,10):
t.insert(1.0,'0123456789
')
a = 'test_mark'
def forwardChars():
# 直接连接字符串
# t.mark_set(a,CURRENT + '+ 5 chars')
t.mark_set(a,CURRENT + '+5c')
def backwardChars():
# t.mark_set(a,CURRENT + '- 5 chars')
t.mark_set(a,CURRENT + '-5c')
def forwardLines():
# t.mark_set(a,CURRENT + '+ 5 lines)
t.mark_set(a,CURRENT + '+5l')
def backwardLines():
# t.mark_set(a,CURRENT + '- 5 lines)
t.mark_set(a,CURRENT + '-5l')
def lineStart():
# 注意linestart前面的那个空格不可省略
t.mark_set(a,CURRENT + ' linestart')
def lineEnd():
# 注意lineend前面的那个空格不可省略
t.mark_set(a,CURRENT + ' lineend')
def wordStart():
# 移动到当前字的开始。
t.mark_set(a,CURRENT + ' wordstart')
def wordend():
# 移动到当前字的结束
t.mark_set(a,CURRENT + ' wordend')
# mark:test_mark默认值为CURRENT
t.mark_set(a,CURRENT)
Button(root,text = 'forward 5 chars',command = forwardChars).pack(fill = X)
Button(root,text = 'backward 5 chars',command = backwardChars).pack(fill = X)
Button(root,text = 'forward 5 lines',command = forwardLines).pack(fill = X)
Button(root,text = 'backward 5 lines',command = backwardLines).pack(fill = X)
Button(root,text = 'line start',command = lineStart).pack(fill = X)
Button(root,text = 'line end',command = lineEnd).pack(fill = X)
Button(root,text = 'word start',command = lineEnd).pack(fill = X)
Button(root,text = 'word end',command = lineEnd).pack(fill = X)
# 测试三个位置的不同,CURRENT可以得知是当前光标的位置;mark就表示mark的位置了,
#INSERT好像一植都在1.0处没有改变。
def insertText():
t.insert(INSERT,'insert')
def currentText():
t.insert(CURRENT,'current')
def markText():
t.insert(a,'mark')
Button(root,text = 'insert jcodeer.cublog.cn',command = insertText).pack(fill = X)
Button(root,text = 'current jcodeer.cublog.cn',command = currentText).pack(fill = X)
Button(root,text = 'mark jcodeer.cublog.cn',command = markText).pack(fill = X)
t.pack()
root.mainloop()