2022-01-29-python-gtk-scale-value-changed-event-handler.md (1141B)
1 title: Handling Python/GTK's GtkScale value-changed event. 2 date: 2022-01-29 00:00 3 --- 4 5 It took me way too long, but now I know how to handle the value-changed event of GtkScale. 6 7 In Glade: 8 9 1. Create a GtkScale widget. We will ID it `foo_scale`. 10 2. In the `Signals -> GtkRange -> value-changed` line change the `Handler` 11 field to something sensible like `on_foo_scale_value_changed`. That will 12 be the name of the handler. 13 3. Make a new Adjustment in: 14 15 ``` 16 General -> 17 Adjustment -> 18 (little pen button in the field) -> 19 Choose a [sic] Adjustment in this project -> 20 New 21 ``` 22 23 4. Rename the adjustment to something sensible like `foo_adjustment` and set 24 the `Value`, `Minimum Value`, `Maximum Value`, etc. Those are kind of self 25 explanatory… 26 5. In Python, your handler will be called with a single argument - the signal 27 emitting object, which is the GtkScale object itself. It has a method, 28 `get_value()`, used to get its current value: 29 30 ```python 31 def on_foo_scale_value_changed(emitter): 32 scale_value = emitter.get_value() 33 do_stuff_with_scale_value(scale_value) 34 ``` 35 36 Fin.