我希望能够在Tkinter Text小部件中双击test,
,并让它选择测试(并排除逗号)。如何修改Tkinter Text小部件中的当前选择长度?
这里是我试过:
import Tkinter as tk
def selection_mod(event=None):
result = aText.selection_get().find(',')
if result > 0:
try:
aText.tag_add("sel", "sel.first", "sel.last-1c")
except tk.TclError:
pass
lord = tk.Tk()
aText = tk.Text(lord, font=("Georgia", "12"))
aText.grid()
aText.bind("<Double-Button-1>", selection_mod)
lord.mainloop()
的第一个问题是<Double-Button-1>
似乎触发处理程序作出选择之前,生产:
TclError: PRIMARY selection doesn't exist or form "STRING" not defined
第二个问题是,即使使用有效的绑定,
我的选择标签似乎没有做任何事情。
它甚至没有提出错误,我试过没有except tk.TclError:
。
我最近发现了如何设置用tcl选择的字符。 [链接](http://stackoverflow.com/a/28133301/1217270) – 2015-01-26 23:17:04