Austin
Austin

Reputation: 51

How can I change the format of Python GTK3 SpinButton displayed text?

Basing my code on this allegedly Python-specific documentation example, I have:

def on_output(spin):
    adj = spin.get_adjustment()
    val = int(adj.get_value())
    s = "%02d" % val
    print "on_output: %s" % s
    spin.set_text(s)

which I connect to my SpinButton's "output" signal. It seems to work when the control is first displayed (shows "00"), but when I click SpinButton's increment button, the formatted value from on_output is overwritten, so e.g. my "01" is shown as plain "1". Looks like another signal or event is causing the control to reformat itself after on_output, but I'm struggling a bit to diagnose. Any experts on GTK3 with Python, please help with debugging suggestions.

Platform is Xubuntu 18.10, Python 2.7, GTK3 3.22.

Upvotes: 0

Views: 132

Answers (1)

Austin
Austin

Reputation: 51

Wow! If ever there was a case for responding with 'RTFM!' this was it. As very politely pointed out by Alexander Dmitriev, the 'return' statement is missing. In my first attempt, I returned True, but it failed (for some presumably unrelated reason) so I tried False which made no difference. Somehow, the return value got lost after that, and when I re-read the doco 'carefully' I missed seeing it -- we see what we expect to see! I must be getting too old for this hacking game, maybe time to hang up my keyboard. :)

Upvotes: 0

Related Questions