ウィンドウのすべてのボタンでフォーカスを無効にしたいのですが。1つのボタンを無効にすることはできますがwidget.set_can_focus(False)
、この機能をウィンドウ内のすべてのボタンに適用するための標準的な方法を知りたいです。
参考までに、私はコンテナを使用HBox
しています。VBox
ボタンのリストを反復処理してから、「ダックタイピング」を使用してフォーカスを無効にします。
例えば:
button_widgets = [button1, button2, ..., buttonN]
for button in button_widgets:
button.set_can_focus(False)
アップデート:
HBox または VBox 内のすべての要素をループしてボタンを見つける方法:
ボタンを含む最下層に HBoxes または VBoxes の名前がある場合は、単純にそれらをループして、ボタンをチェックしてからリストに追加できます。HBox 内のすべてのボタンを出力する例を次に示します。
import gtk
import pygtk
hbox = gtk.HBox()
button1 = gtk.Button('1')
button2 = gtk.Button('2')
hbox.add(button1)
hbox.add(button2)
for i in hbox:
if type(i) == gtk.Button: print i
出力:
<gtk.Button object at 0x1909320 (GtkButton at 0x171e8e0)>
<gtk.Button object at 0x19093c0 (GtkButton at 0x171e9a0)>