简体   繁体   English

在运行时无法向wxpython GUI添加复选框

[英]Unable to add checkbox to wxpython GUI during runtime

I am attempting to added checkboxes to a wxpython gui during runtime, but it does not seem to be showing up. 我正在尝试在运行时将复选框添加到wxpython gui中,但是似乎没有显示出来。 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. 我尝试按照帖子< 在运行时在wxPython中添加复选框 >,但无法使其正常工作。 I also used wxFormBuilder to see how it adds a checkbox during initialization; 我还使用了wxFormBuilder来查看它如何在初始化期间添加一个复选框。 I was able to verify that self.mainWindow.p_SelectionPanel is where I want to add the checkbox. 我能够验证self.mainWindow.p_SelectionPanel是我要添加复选框的位置。 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. 有关该应用程序的更多背景知识:它是一个wxPython GUI,其中嵌入了matplotlib图。 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. point是一个字典,键为系列名称,而系列值为字典值。

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()

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 >. 通过使用这里介绍的技术,我已经能够“移交”复选框到主线程中:< 在Python中的线程之间共享数据 >。

Though, a better, thread-safe way to structure my program is suggested here: < WxPython: Periodically set value in TextCtrl not working >. 但是,在这里建议了一种更好的,线程安全的方法来构建程序结构:< WxPython:定期在TextCtrl中设置值不起作用 >。 There is also a way that avoids the use of multiple threads noted, too. 还有一种避免使用多个提到的线程的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM