Good night everyone,
I have a mainframe with a list control(which is populated by a database) and some buttons. The new button opens another frame(which has a class of its own) in which the user can input text and select some options. I want when the user presses the create button from that new frame:
- the database should be updated with the users input(I have achieved this)
- the update function from the mainframe should be called to update the list with the new items(this is where I am stuck)
Can someone please assist me. I dont want to get stuck with using a refresh button. Thanks in advance.
I use the pubsub (publisher-subscriber) package to do operations like this.
Basically the class that needs to send the information calls pub.sendMessage() and the class that needs to receive the information calls pub.subscribe() to register a handler method to process the information. If appropriate, multiple classes can register to receive the same message. I find it works very well.
The pubsub package is still included with wxPython 4.1.1, but because it is so useful outside of wxPython it was also made available as a separate stand-alone package. Due to this, use of the version in wxPython is now deprecated, so I use the stand-alone version instead. This can be installed using:
pip install PyPubSub
Here are some useful links:
https://pypubsub.readthedocs.io/en/v4.0.3/
https://wiki.wxpython.org/WxLibPubSub
http://www.blog.pythonlibrary.org/2013/09/05/wxpython-2-9-and-the-newer-pubsub-api-a-simple-tutorial/
The last 2 links describe the use of the pubsub package that is included in wxPython. If you are using the stand-alone package you need to change the import statements they use from:
from wx.lib.pubsub import pub
to:
from pubsub import pub