0

I am attempting to added checkboxes to a wxpython gui during runtime, but it does not seem to be showing up. My code is below.

I have tried following the post < Add checkbox in wxPython in runtime >, but was not able to get it to work. I also used wxFormBuilder to see how it adds a checkbox during initialization; I was able to verify that self.mainWindow.p_SelectionPanel is where I want to add the checkbox. I have also checked with the debugger to ensure that each line of the code is run at least once.

A little more background about the application: it is a wxPython GUI with a matplotlib plot embedded into it. I am trying to generate checkboxes from an incoming serial port stream so the user can show/hide series during runtime. point is a dictionary with the key as the series name and the series value as the dictionary value.

Please let me know if you need more context.

Thanks in advance for the help.

 def addNewCheckBoxes(self,point):
        sizer = self.mainWindow.p_SelectionPanel.GetSizer()
        addedCheckBox = False

        for key in point.keys():
            if key not in self.cbList.keys():
                self.cbList[key] = wx.CheckBox(self.mainWindow.p_SelectionPanel)
                sizer.Add(self.cbList[key])
                addedCheckBox = True

        if addedCheckBox:
            self.mainWindow.p_SelectionPanel.SetSizer(sizer)
            self.mainWindow.p_SelectionPanel.Layout()
Community
  • 1
  • 1
apandit
  • 808
  • 1
  • 7
  • 16
  • 1
    call Layout on mainWindow since its size may have changed – stark Jan 06 '15 at 22:14
  • Thanks for the suggestion stark! I tried this, but the checkbox is not showing up on the GUI. I think the problem may be that I am using two threads: the main thread and a thread to manage the serial data retrieval/plot update. I will investigate further... – apandit Jan 09 '15 at 15:21
  • Not sure about wx, but in tk all GUI operations must be on one thread. Generally no reason to make GUI multi-threaded. – stark Jan 09 '15 at 15:38

1 Answers1

0

This issue is cause by utilizing multiple threads; see comments above. I have been able to "hand off" the addition of check boxes to the main thread by using the techniques addressed here: < Sharing data between threads in Python >.

Though, a better, thread-safe way to structure my program is suggested here: < WxPython: Periodically set value in TextCtrl not working >. There is also a way that avoids the use of multiple threads noted, too.

Community
  • 1
  • 1
apandit
  • 808
  • 1
  • 7
  • 16