gpt4 book ai didi

python - ttk.Entry.select_range() 适用于 Button,但不适用于 python/tkinter 中的 ttk.Button?

转载 作者:行者123 更新时间:2023-12-01 05:06:00 27 4
gpt4 key购买 nike

有人可以解释一下为什么entry.select_range()适用于Button,但不适用于ttk.Button吗?

from tkinter import *
from tkinter import ttk

root = Tk()

entry = ttk.Entry(root)
entry.pack()

#This works
button = Button(root, text="Select your text", command=lambda:
entry.select_range(0, END))

#but this doesn't
##button = ttk.Button(root, text="Select your text", command=lambda:
## entry.select_range(0, END))

button.pack()

root.mainloop()

最佳答案

这个答案来自Google Group说,

However, on Windows (only) the selection will only become visible when the entry gets the focus.

还有此页面关于ttk button说,

By default, a ttk.Button will be included in focus traversal ... To remove the widget from focus traversal, use takefocus=False

所以你需要为ttk.Button添加takefocus选项。

button = ttk.Button(root, takefocus=False, text=...)

关于python - ttk.Entry.select_range() 适用于 Button,但不适用于 python/tkinter 中的 ttk.Button?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25039390/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com