# How to get the current value of a Gtk scale widget

**URL:** https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680
**Category:** New to Julia
**Created:** [September 30, 2018, 1:21am UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680 "2018-09-30T01:21:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![rverdier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rverdier/32/9104_2.png) [@rverdier](https://discourse.julialang.org/u/rverdier)
#### Post date: [September 30, 2018, 1:21am UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680/1 "2018-09-30T01:21:50Z")

</div>

I’m trying to learn Julia by converting some of my Python apps to it. I’m using gtk because Tk no longer builds in Julia 1.0. I’ve hit a brick wall trying to get the value of a GtkScale widget. Here’s an example:

# Gtk scale widget test

using Gtk  
win = GtkWindow()  
s = GtkScale(false, 0:10)  
function scaleset(widget)  
if widget == s  
println(“widget==scale”)  
end  
println(“scale changed”)  
end  
push!(win, s)  
id = signal\_connect(scaleset, s, “value\_changed”)  
showall(win)

This correctly calls the callback function scaleset when the slider is dragged. I need to get the new value of the scale at that point, which is trivial in Python, Java, C#, …, but I can find no documentation that tells how to do it in Julia. I’ve read that the value is stored in the parent GtkRange but I don’t know how to access that. REPL help says “Binding GtkRange does not exist.”

Can anybody tell me how to get the value, or, even better, point me to valid documentation for this? Many thanks for any help.

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [September 30, 2018, 8:06am UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680/2 "2018-09-30T08:06:48Z")

</div>

looks to me like get\_value is missing in Gtk.jl. I’d recommend to put an issue there.

---

<div class="post-metadata">

### Author: ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)
#### Post date: [September 30, 2018, 9:35am UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680/3 "2018-09-30T09:35:43Z")

</div>

a = Gtk.GAccessor.adjustment(s)  
value = Gtk.get\_gtk\_property(a,“value”,Float64)

(edit: jonathans syntax below is recommended)

---

<div class="post-metadata">

### Author: ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)
#### Post date: [September 30, 2018, 9:35am UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680/4 "2018-09-30T09:35:54Z")

</div>

Here’s two ways to do it (using the new getproperty syntax):

```julia
function scaleset(widget)
    println( Gtk.GAccessor.value(widget) ) 
    adj = s.adjustment[GtkAdjustment]
    println( adj.value[Float64] ) 
end

```

What I usually do is look in Gtk docs for properties that I can use. If there no properties then I look for a method and I just search that method name in the Gtk.jl repo. In that case I found [this](https://github.com/JuliaGraphics/Gtk.jl/blob/fe6739a3a345ba804030c8d379daa15f30055903/gen/gbox3#L4076). All the methods there have been automatically wrapped with `Clang.jl`, and they are in the submodule `Gtk.GAccessor`.

---

<div class="post-metadata">

### Author: ![tobias.knopp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobias.knopp/32/7551_2.png) [@tobias.knopp](https://discourse.julialang.org/u/tobias.knopp)
#### Post date: [September 30, 2018, 9:44am UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680/5 "2018-09-30T09:44:09Z")

</div>

Is far as I have understood one usually uses the `GtkAdjustment` to communicate with a scale or a spin button. In that way you can exchange the visual representation.

I do my UI fully in glade and the create the GtkAdjustment + SpinButton from there and also connect them there. In julia I then just need to communicate with the Adjustment.

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [September 30, 2018, 12:09pm UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680/6 "2018-09-30T12:09:55Z")

</div>

With [GtkReactive](https://github.com/JuliaGizmos/GtkReactive.jl) it’s just

```julia
julia> using Gtk.ShortNames, GtkReactive

julia> win = Window("slider") |> (sl = slider(1:10)); Gtk.showall(win);

julia> value(sl)
5

```

---

<div class="post-metadata">

### Author: ![rverdier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rverdier/32/9104_2.png) [@rverdier](https://discourse.julialang.org/u/rverdier)
#### Post date: [October 1, 2018, 2:04am UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680/7 "2018-10-01T02:04:38Z")

</div>

These are exactly what I needed. And they suggested the way to reset the Scale limits dynamically, which I also need to do, using Gtk.GAccessor.range(s,newmin,newmax). Thanks very much!

---

<div class="post-metadata">

### Author: ![rverdier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rverdier/32/9104_2.png) [@rverdier](https://discourse.julialang.org/u/rverdier)
#### Post date: [October 1, 2018, 2:12am UTC](https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680/8 "2018-10-01T02:12:11Z")

</div>

Thanks. I’d tried to use GtkReactive, but the package manager failed to add it, apparently because of an error building Tk.jl (!?) which I had tried initially. I’m off and running now with GAccessor.
