0

What's the best way to dispay leading zeros for number in wx.SpinCtrl?

I've created SpinCtrl:

self.MySpin = wx.SpinCtrl(self, min=1, max=100)

and i want that displaying 002, 003... 012 etc when i press up button in this spin

How I can do this?

4

3 回答 3

1

I don't believe it's supported by wxPython. You would have to roll your own widget or modify an existing one. I would look at FloatSpin since it is pure Python. It would be a lot easier to hack than wx.SpinCtrl since SpinCtrl is a wrapped C++ widget.

于 2013-07-12T14:45:01.483 回答
1

我认为没有任何方法可以做到这一点,您需要手动使用wxSpinButton绑定到 a 。wxTextCtrl

于 2013-07-12T13:30:06.870 回答
0

为了解决我的问题,我已将小部件 wx.SpinCtrl 更改为 wx.SpinButton(在此答案中推荐用户 VZ。 ),并且我创建LeadingSpinButton了从 wx.SpinButton 继承的新类并添加GetLeadingValue方法leading_widthleading_char属性。

class LeadingSpinButton(wx.SpinButton):

    def __init__(self, parent, style, leading_width=0, leading_char='0'):
        wx.SpinButton.__init__(self, parent=parent, style=style)
        self.leading_width = leading_width
        self.leading_char = leading_char

    def GetLeadingValue(self):
        """GetLeadingValue(self) -> str"""
        value = str(self.GetValue())
        value = value.rjust(self.leading_width, self.leading_char)
        return value

我的解决方案如何?

于 2013-07-15T11:07:13.963 回答