![](/img/trans.png)
[英]How to read the text below the mouse when clicking on a tkinter Text widget and paste it in an Entry widget?
[英]defining what characters are selected when double clicking in a Text widget
在Windows上,双击“文本”小部件中的单词也会选择连接的标点符号。
有什么方法可以定义要选择的字符?
tcl_wordchars
此变量的值是一个正则表达式,可以将其设置为控制哪些字符被视为“单词”字符,例如,通过双击Tk中的文本来选择单词。 它取决于平台。 在Windows上,它默认为\\ S,表示Unicode空格字符以外的任何内容。 否则,默认为\\ w,它是任何Unicode单词字符(数字,字母或下划线)。
这是Python 3.4的示例:
import tkinter
class Creator(object):
def __init__(self):
root = self.root = tkinter.Tk()
# Main Frame
f_main = tkinter.Frame(root, borderwidth=6, relief='flat')
f_main.grid(row=0, column=0, sticky='nsew')
# Text widget and frame
f_txt = tkinter.Frame(f_main, borderwidth=2, relief="sunken")
f_txt.config(width=768, height=768)
f_txt.pack(padx=4, pady=4, side="bottom", fill="both", expand=True)
my_txt = self.text = tkinter.Text(f_txt)
my_txt.config(undo=True, wrap='word')
my_txt.grid(row=0, column=0, sticky="nsew")
my_txt.focus_set()
GUI = Creator()
GUI.root.tk.eval("catch {tcl_endOfWord}")
GUI.root.tk.eval("catch {tcl_startOfPreviousWord}")
GUI.root.tk.eval("set tcl_wordchars {[[:alnum:]']}")
GUI.root.tk.eval("set tcl_nonwordchars {[^[:alnum:]']}")
GUI.root.mainloop()
来自http://wiki.tcl.tk/1655的注释:
...要更改有效的字符,您必须首先执行以下操作:
赶上{tcl_endOfWord}
可以在这里研究regex语法: https : //www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.