我正在尝试弄清楚如何在我的文本小部件中突出显示我设置了焦点的文本。因此,用户只需单击应用程序,输入,然后按enter,而不必单击以突出显示更改文本。有谁知道这是不是可以做到?
当前GUI:
window.geometry('375x125')
window.title("VPLS Lookup Tool")
version = Label(window, text='VPLS Lookup Tool v.1.1')
version.grid(column=1, row=0)
vplsnumber = Label(window, text='VPLS Number:')
vplsnumber.grid(column=0, row=1)
vpls = Entry(window,width=10)
vpls.focus_set()
vpls.grid(column=1, row=1)
#Placing the button and what specifying what to do when clicked
btn = Button(window, text="Navigate to File", command=clicked)
btn.grid(column=1, row=2)
addpath = Button(window, text="Mount K Drive", command=clicked2)
addpath.grid(column=1, row=3)
window.bind('<Return>', Keyboard_Entry)
window.bind('<KP_Enter>', Keyboard_Entry)
window.mainloop()```发布于 2019-11-14 00:35:33
如果我理解这个问题,您想使用select_range方法。这将选择准备替换、删除或复制的文本字符。它包含在<FocusIn>的回调函数中
import tkinter as tk
def select_on_focus(event):
event.widget.select_range(0, tk.END) # Select all the text in the widget.
root = tk.Tk()
ent = tk.Entry(root)
ent.grid()
ent.focus_set()
ent.insert(0, 'abcde')
ent.bind('<FocusIn>', select_on_focus)
root.mainloop()https://stackoverflow.com/questions/58838658
复制相似问题