Pygtk-spinbutton-class
提供:Dev Guides
PyGTK-SpinButtonクラス
しばしばSpinnerと呼ばれるSpinnButtonウィジェットは、右に上下の矢印があるgtk.Entryウィジェットです。 ユーザーは、数値を直接入力するか、上下の矢印を使用して増減できます。 gtk.SpinButtonクラスは、gtk.Entryクラスから継承されます。 スピナーの数値の範囲とステップを制限できるgtk.Adjustmentオブジェクトを使用します。
SpinButtonウィジェットは、次のコンストラクタを使用して作成されます-
ここで、adjは範囲を制御する* gtk.Adjustmentオブジェクトを表し、 climb_rate は加速係数であり、数字で指定された小数の数です。
gtk.SpinButtonクラスには次のメソッドがあります-
- SpinButton.set_adjustment()-これは「調整」プロパティを設定します。
- SpinButton.set_digits()-これは、「digits」プロパティを値に設定して、スピンボタンによって表示される小数点以下の桁数を決定します。
- SpinButton.set_increments(step、page)-左マウスボタンを押すたびに増分が適用されるステップ値と、中ボタンを押すたびに増分が適用されるページ値を設定します。
- SpinButton.set_range()-これは、スピンボタンの最小値と最大値を設定します。
- SpinButton.set_value()-これは、スピンボタンを新しい値にプログラムで設定します。
- SpinButton.update_policy()-有効な値はgtk.UPDATE_ALWAYSとgtk.UPDATE_VALIDです
- SpinButton.spin(direction、increment = 1)-これは、指定された方向にスピナーの値を増分または減分します。
以下は、事前定義された方向定数です-
gtk.SPIN_STEP_FORWARD | forward by step_increment |
gtk.SPIN_STEP_BACKWARD | backward by step_increment |
gtk.SPIN_PAGE_FORWARD | forward by step_increment |
gtk.SPIN_PAGE_BACKWARD | backward by step_increment |
gtk.SPIN_HOME | move to minimum value |
gtk.SPIN_END | move to maximum value |
gtk.SPIN_USER_DEFINED | add increment to the value |
gtk.SpinButtonウィジェットは、次の信号を発します-
change-value | This is emitted when the spinbutton value is changed by keyboard action |
input | This is emitted when the value changes. |
output | This is emitted when the spinbutton display value is changed. Returns* True* if the handler successfully sets the text and no further processing is required. |
value-changed | This is emitted when any of the settings that change the display of the spinbutton is changed. |
wrapped | This is emitted right after the spinbutton wraps from its maximum to minimum value or vice-versa. |
例
次の例では、3つのSpinButtonウィジェットを使用して、単純な Date Selector を構築します。 Day Selectorは、1〜31の値を制限する調整オブジェクトに適用されます。 2番目のセレクターは、月1〜12の数用です。 3番目のセレクタは、2000〜2020年の範囲を選択します。
コードを観察します-
実行すると、上記のコードは次の出力を生成します-