python 文本全选

这个是一个控制框有效果

# encoding: utf-8

from Tkinter import *

def printentry(event):
    print("click on", event.x, event.y)
    print entry.get()
    print len(entry.get())
    entry.insert(len(entry.get()),"abc")
    entry.selection_range(0, len(entry.get()))

root=Tk()
var=StringVar()
var.set("int")
entry = Entry(root,text="")
entry.place(x=0, y=0, anchor=NW)
entry = Entry(root,textvariable=var)
entry.place(x=0, y=20, anchor=NW)
# entry.bind(sequence="<Button-1>", func=printentry)   #光单击鼠标左键不响应事件,它需要一个释放鼠标左键的事件来触发事件
entry.bind(sequence="<Button-1><ButtonRelease-1>", func=printentry)  #单击鼠标左键
# entry.bind(sequence="<Double-Button-1><ButtonRelease-1>", func=printentry)  #双击鼠标左键
root.mainloop()

 

posted @ 2018-08-07 16:21  Anita_harbour  阅读(1299)  评论(0编辑  收藏  举报