zoukankan      html  css  js  c++  java
  • Tkinter教程之Text篇(1)

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

  • 相关阅读:
    JS中的this
    VS下遇到未能加载文件或程序集 错误
    观察者模式实现INotifyPropertyChanged
    看书不仔细的下场
    Android 解析XML
    杂想
    Android 对话框用法
    Android之AlertDialog.Builder详解
    Android:开机自启动并接收推送消息
    Clojure:通过ZeroMQ推送消息
  • 原文地址:https://www.cnblogs.com/rosesmall/p/3480438.html
Copyright © 2011-2022 走看看