Displaying leading zero in gtk.SpinButton

I would like to have a leading zero in the spin bounce so that two digits are always displayed.

adj_hour = gtk.Adjustment(int(time.strftime("%H")),0,24,1,1)
entry_hour = gtk.SpinButton()
entry_hour.set_adjustment(adj_hour)

the problem is that gtk. The first argument to configure is float / int.

I tried things like:

adj_hour = gtk.Adjustment(float(format(int(time.strftime("%H")), '02d')),0,24,1,1)

but that will not work.

+5
source share
1 answer

Connect to the outputrotation button signal . For example, adapting the C code in the documentation I am attached to:

def show_leading_zeros(spin_button):
    adjustment = spin_button.get_adjustment()
    spin_button.set_text('{:02d}'.format(int(adjustment.get_value())))
    return True

...

entry_hour.connect('output', show_leading_zeros)
+5
source

All Articles