0

I am designing a GUI for instrumentation control using wxPython. I am first setting up all the fields and controls I need. Among those controls are SpinCtrlDouble I use to define frequencies and amplitudes with 3 digits at least. I realised that the float in SpinCtrlDouble was not displayed properly when I have SetDigits() with any number above 2. See the screenshot : floats appear selected and also shifted so you cannot see the first few numbers. Here it should display 21.62100, but the text is shifted so you cannot see the 21. How could I sort this out ? I tried to align the text in the SpinCtrlDouble with wx.TE_RIGHT but it did not change anything. I also tried to span it even more but same problem again.

Edit : I run this program on Win10, with Python3.11.5, wxPython-4.2.3. I use Visual Studio Code IDE. Problem is identical with Python3.9.21 and Python3.13.4.

GUI example of the problem

import wx

class Mywin(wx.Frame): 
    def __init__(self): 
        wx.Frame.__init__(self, None, title = 'Hello')
        # main panel window
        panel = wx.Panel(self)        
        # main vbox
        vbox = wx.BoxSizer(wx.VERTICAL)
        # vbox.SetMinSize(self,(600,800))

        # StaticBoxSizer for Keithley controls
        BoxKeithleySizer = wx.StaticBoxSizer(wx.VERTICAL, panel, 'Keithley :') # StaticBox with edge and title
        BoxKeithleyGrid = wx.GridBagSizer(hgap=5, vgap=5) # add widgets to this
        toto = BoxKeithleySizer.GetStaticBox()
        toto.SetBackgroundColour((255, 201, 201)) # set background color of the StaticBox

        # widgets to go in the StaticBoxSizer for Keithley controls
        TextKeithleyFreq = wx.StaticText(BoxKeithleySizer.GetStaticBox(), -1, "Freq.")
        BoxKeithleyFreq = wx.SpinCtrlDouble(BoxKeithleySizer.GetStaticBox(), -1)
        UnitKeithleyFreq = wx.StaticText(BoxKeithleySizer.GetStaticBox(), -1, "MHz")

        BoxKeithleyFreq.SetDigits(5)
        BoxKeithleyFreq.SetIncrement(0.001)
        BoxKeithleyFreq.SetMin(21.600)
        BoxKeithleyFreq.SetMax(21.650)
        BoxKeithleyFreq.SetValue(21.621)

        # add widgets to the StaticBoxSizer for Keithley controls
        BoxKeithleyGrid.Add(TextKeithleyFreq, pos=(0,0), flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        BoxKeithleyGrid.Add(BoxKeithleyFreq, pos=(0,1), span=(1,5), flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)
        BoxKeithleyGrid.Add(UnitKeithleyFreq, pos=(0,6), flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL)

        BoxKeithleySizer.Add(BoxKeithleyGrid)
        # add Sizers to main vbox and panel
        vbox.Add(BoxKeithleySizer,0, wx.ALL|wx.LEFT, 5)
        panel.SetSizer(vbox)

class MyApp(wx.App):
    def OnInit(self):

        frame = Mywin()
        frame.Show()
        self.SetTopWindow(frame)

        return True

def main():
    app = MyApp(redirect=False)
    app.MainLoop()

if __name__ == "__main__" :
    main()

4
  • 1
    Cannot reproduce on Linux Mint (22.1 Cinnamon, wxPython 4.2.3, Python 3.13). Maybe add the operating system and versions you are working with. Commented Jun 5 at 10:42
  • 1
    ditto @simon, cannot reproduce ( macos python 3.13.3, wx 4.2.3 ) Commented Jun 5 at 10:56
  • 1
    @simon Added OS and version in edit. I also tried to run the program outside of IDE, did not help. Commented Jun 5 at 14:22
  • Like the others I cannot reproduce it but I know sounds silly but as you aren't using those 5 digits, try setting 'BoxKeithleyFreq.SetDigits(3)' and see if your platform works with that. Commented Jul 6 at 16:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.