首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在第一个“焦点”调用后更改焦点

问无法在第一个“焦点”调用后更改焦点
EN

Stack Overflow用户
提问于 2020-02-28 01:33:22
回答 1查看 55关注 0票数 0

在TCL中,我发现在第一个focus调用之后不能改变焦点

这是一个MRE:

代码语言:javascript
复制
frame .f -padx 15 -pady 15

spinbox .f.spin1 -from 0 -to 10 -width 5 -relief solid -highlightthickness 1 -highlightcolor blue -borderwidth 1 -textvariable ::a
spinbox .f.spin2 -from 0 -to 10  -width 5 -relief solid -highlightthickness 1 -highlightcolor blue -borderwidth 1 -textvariable ::b
spinbox .f.spin3 -from 0 -to 10 -width 5 -relief solid -highlightthickness 1 -highlightcolor blue -borderwidth 1 -textvariable ::c

# note that changing the focus in the bindings works as expected
bind .f.spin1 <Key> { if {"%K" eq "Left"} { focus .f.spin3 } }
bind .f.spin1 <Key> {+ if {"%K" eq "Right"} { focus .f.spin2 } }

bind .f.spin2 <Key> { if {"%K" eq "Left"} { focus .f.spin1 } }
bind .f.spin2 <Key> {+ if {"%K" eq "Right"} { focus .f.spin3 } }

bind .f.spin3 <Key> { if {"%K" eq "Left"} { focus .f.spin2 } }
bind .f.spin3 <Key> {+ if {"%K" eq "Right"} { focus .f.spin1 } }

pack .f
grid .f.spin1 -column 1 -row 0
grid .f.spin2 -column 2 -row 0
grid .f.spin3 -column 3 -row 0

# with no focus invocation, no spinbox will be focused when the window opens
# we'll call focus on spin2 as default

# this works as expected
focus -force .f.spin2

# if some condition is met we want to change the focus to spin3
# but the following invocation doesn't change the focus
if { 1 } {
    focus -force .f.spin3
}

我也尝试过(没有成功)专注于spin3之前的帧

代码语言:javascript
复制
focus -force .f.spin2
focus -force .f
focus -force .f.spin3

我确实尝试过(同样没有成功)使用after idle

代码语言:javascript
复制
after idle { focus -force .f.spin3 }

真正起作用的是使用after 1000,但它在代码方面并不优雅。并且对用户也不好,因为他可能在焦点改变之前键入。我尝试过较小的值,但焦点不会因为较小的值而改变,因此这不是一个可靠的解决方案。

为什么会发生这种情况?我怎么才能修复它?

编辑:(不确定是否相关,但我在Win10上)

EN

回答 1

Stack Overflow用户

发布于 2020-02-28 04:03:15

这个错误也出现在Linux上。我为此打开了一个ticket。

解决方法1:

代码语言:javascript
复制
update
focus -force .f.spin3

解决方法2:

代码语言:javascript
复制
after 100 [list focus -force .f.spin3]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60438845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档