gpt4 book ai didi

python - GTK 焦点链

转载 作者:行者123 更新时间:2023-12-01 15:18:31 25 4
gpt4 key购买 nike

目前我正在开发一个 pyGTK3 应用程序,我想为其设置焦点链。当使用下面的代码(简化版)时,会发生一些有趣的事情 GTK 正确地聚焦在第一个按钮上,但在 tab 上没有任何反应。

起初我以为这是因为GTK不知道链条,但后来我尝试了shift+tab 导致链条的最后一个元素获得了焦点哪个是正确的。另一个 shift+tab 不会将焦点从最后一个按钮移开。

所以我认为他们的代码有问题,我需要手动更新链顺序吗?或者我遗漏了什么?

class Screen(Gtk.Grid):
def __init__(self, parent, core, video_widget):
Gtk.Grid.__init__(self)

# adds the control buttons
self.controls = load_controls(self)

self.set_focus_chain((self.controls.play, self.controls.backward, self.controls.recording))

最佳答案

为了设置容器内元素的焦点链,需要先将父元素的焦点链设置到容器。从那里需要设置容器的焦点链。

因此代码需要如下:

# Points Gtk toward the container first
self.set_focus_chain([self.controls])

# Sets the focus chain inside the container
self.controls.set_focus_chain((self.controls.play, self.controls.backward, self.controls.recording, self.controls.end_inspection))

因此,似乎 GTK 只允许将焦点链指向 child ,因此要求用户设置焦点链以将焦点链设置为孙子。

关于python - GTK 焦点链,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35067755/

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