【问题标题】:How to display a leading zeros for number in wx.SpinCtrl?如何在 wx.SpinCtrl 中显示数字的前导零?
【发布时间】:2013-07-12 12:24:15
【问题描述】:

在 wx.SpinCtrl 中显示数字前导零的最佳方法是什么?

我已经创建了 SpinCtrl:

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

我希望显示 002、003... 012 等 当我在这个旋转中按下向上按钮时

我该怎么做?

【问题讨论】:

    标签: python user-interface wxpython wxwidgets


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我不相信 wxPython 支持它。您将不得不推出自己的小部件或修改现有的小部件。我会看看 FloatSpin,因为它是纯 Python。它比 wx.SpinCtrl 更容易破解,因为 SpinCtrl 是一个封装的 C++ 小部件。

      【讨论】:

        【解决方案3】:

        为了解决我的问题,我将小部件 wx.SpinCtrl 更改为 wx.SpinButton(推荐用户 VZ。在此 answer 中)并且我创建了继承自 wx.SpinButton 的新类 LeadingSpinButton 并添加 @987654323 @ 方法,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
        

        我的解决方案如何?

        【讨论】:

          猜你喜欢
          • 2010-09-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多