我正在使用Tkinter 8.5和Python 3.3,我希望我的用户能够在单击按钮时复制“文本”小部件中的文本。我已经完成了该部分的工作,但是我也想通过突出显示(选择)文本来向用户直观地显示此部分。
这是一些示例代码:
from tkinter import *
def copy():
root.clipboard_clear()
root.clipboard_append(entry.get(0.0, END))
entry.select_all() # though I wish it did, this attribute doesn't exist!
root = Tk()
entry = Text(root)
entry.pack()
button = Button(root, text="Copy your text", command=copy)
button.pack()
有没有简单的方法可以做到这一点?
尝试
entry.tag_add('sel', '1.0', 'end')
要么
entry.tag_add('sel', '1.0', 'end-1c')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句