我是一个有用的助手,可以为您翻译文本。
我正在使用Python 2.7编写一个Tkinter应用程序。我正在使用wordstart和wordend索引来获取单击的单词。这对于常规单词非常有效,但对于连字符单词无效。
以下是我的代码:
如何配置才能使打印用户在不分割连字符的情况下打印整个连字符词?例如,当您点击位置不同时,打印字符串"dashes-between"而不是"dashes"、"between"或"-"。
我正在使用Python 2.7编写一个Tkinter应用程序。我正在使用wordstart和wordend索引来获取单击的单词。这对于常规单词非常有效,但对于连字符单词无效。
以下是我的代码:
from Tkinter import *
master = Tk()
def userOptions(event, clickposition):
index1 = clickposition + " wordstart"
index2 = clickposition + " wordend"
user = text.get(index1, index2)
print user
return
def userEnter(event):
text.config(cursor="hand2")
return
def userLeave(event):
text.config(cursor="arrow")
return
text = Text(master)
text.insert(INSERT, "This is a sentence\n")
text.insert(INSERT, "This is a sentence with dashes-between some-words\n")
text.pack()
text.tag_add("click", "1.0", "end")
text.tag_bind("click", "<Enter>", userEnter)
text.tag_bind("click", "<Leave>", userLeave)
text.tag_bind("click", "<Button-1>", lambda event: userOptions(event, text.index("@%d,%d" % (event.x, event.y))))
text.config(state = DISABLED)
master.mainloop()
如何配置才能使打印用户在不分割连字符的情况下打印整个连字符词?例如,当您点击位置不同时,打印字符串"dashes-between"而不是"dashes"、"between"或"-"。