在gtk.SpinButton中显示前导零 [英] display leading zero in a gtk.SpinButton
本文介绍了在gtk.SpinButton中显示前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在旋转按钮中使用前导零,以便始终显示两位数字.
i'd like to have a leading zero in a spinbutton in order to always have two digits displayed.
adj_hour = gtk.Adjustment(int(time.strftime("%H")),0,24,1,1)
entry_hour = gtk.SpinButton()
entry_hour.set_adjustment(adj_hour)
问题在于gtk.调整项的第一个参数必须为float/int.
problem is that gtk.Adjustment's first argument has to be float/int.
我尝试过类似的事情:
adj_hour = gtk.Adjustment(float(format(int(time.strftime("%H")), '02d')),0,24,1,1)
但它不起作用.
推荐答案
连接到 output
信号.例如,调整我链接到的文档中的C代码:
Connect to the output
signal of the spin button. For example, adapting the C code in the documentation I linked 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)
这篇关于在gtk.SpinButton中显示前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文